Skip to content

refactor: prefer f-strings to .format in docs #13317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2022

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