KEMBAR78
refactor: prefer f-strings to .format in docs by kkirsche · Pull Request #13317 · python/mypy · GitHub
Skip to content

Conversation

kkirsche
Copy link
Contributor

@kkirsche kkirsche commented Aug 3, 2022

Description

Because Mypy currently requires 3.6+, this merge request begins the process of refactoring the use of various format styles such as .format, with the use of f-strings. This intentionally leaves behind certain formatting examples which are being used to demonstrate errors, such as:

    def foo(a):
        return '(' + a.split() + ')'  # No error!

Python added f-strings in version 3.6, with PEP 498. F-strings are a flexible and powerful way to concatenate strings. They make the code shorter and more readable, since the code now looks more like the output. Finally, there is also a performance benefit to using f-strings, which is an additional reason to advocate for their usage in examples.

Finally, this also leverages PEP515, underscores in numeric literals, in two locations, to improve legibility while reading numbers larger than 999 that are not years.

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

…ormat in docs since Mypy requires Python 3.6+
@JelleZijlstra JelleZijlstra merged commit 008b408 into python:master Aug 3, 2022
@kkirsche kkirsche deleted the refactor/f-strings branch August 3, 2022 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants