docs: Specify preferred Python string formatting technique #13718
pull masonicboom wants to merge 1 commits into bitcoin:master from masonicboom:python-string-format-guideline changing 1 files +1 −0-
masonicboom commented at 7:29 pm on July 19, 2018: none@practicalswift this documents the nit you suggested in my previous PR #13707 (review)
-
docs: Specify preferred Python string formatting technique b1b8863fd6
-
practicalswift commented at 8:27 pm on July 19, 2018: contributor
Regarding my suggestion in #13707 (review): it should be noted that a nit is just a suggested change for a trivial often non-blocking issue. Not all style nits end up in the developer notes (due to various reasons: no clear consensus, not worth documenting, etc.).
With that out of the way I’m ACK:ing this PR:
The Python documentation is discouraging the use of the old string formatting style (
'%s' % x
):4.7.2. printf-style String Formatting Note: The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals, the str.format() interface, or template strings may help avoid these errors. Each of these alternatives provides their own trade-offs and benefits of simplicity, flexibility, and/or extensibility.
From older Python 3 documentation about
'%s' % x
:5.6.2. Old String Formatting Operations Note: The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code.
ACK b1b8863fd6fa54fa90f32fd2e384b0f257d0f526
Trivia: When we move to Python 3.6 we can start using formatted string literals (“f-strings”) as well :-)
-
masonicboom commented at 9:00 pm on July 19, 2018: none
Thanks. My philosophy is: if it’s worth a nit, it’s worth documenting (or even better, automating with lint rules) to eliminate review round-trips in the future.
Trivia: When we move to Python 3.6 we can start using formatted string literals (“f-strings”) as well :-)
Nice!
-
practicalswift commented at 9:05 pm on July 19, 2018: contributor@masonicboom I share your love for automation/linting! 🏧😍
-
laanwj commented at 12:49 pm on July 20, 2018: member
Concept ACK, no strong feelings on what formatting to use, and please do not create PRs that change this all over the place, but for new code it is a good idea to use the new, recommended style consistently.
F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code
I really like that! string-formatting as a macro-expression. But it will be a while before 3.6 can be required as minimum without breaking a lot of builds. 3.6.0 was released at the end of 2016.
-
MarcoFalke commented at 1:02 pm on July 20, 2018: member
Agree with @practicalswift and @laanwj
it should be noted that a nit is just a suggested change for a trivial often non-blocking issue. Not all style nits end up in the developer notes (due to various reasons: no clear consensus, not worth documenting, etc.).
-
MarcoFalke added the label Docs on Jul 20, 2018
-
MarcoFalke added the label Tests on Jul 20, 2018
-
MarcoFalke merged this on Jul 20, 2018
-
MarcoFalke closed this on Jul 20, 2018
-
MarcoFalke referenced this in commit f7f574d453 on Jul 20, 2018
-
promag commented at 1:18 pm on July 20, 2018: memberACK
-
PastaPastaPasta referenced this in commit 6e5cc92413 on Jul 17, 2020
-
PastaPastaPasta referenced this in commit 8ad8dbbc2e on Jul 17, 2020
-
PastaPastaPasta referenced this in commit c0f44834b7 on Jul 17, 2020
-
MarcoFalke referenced this in commit 4b24c3962f on Nov 18, 2020
-
MarcoFalke locked this on Sep 8, 2021
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
More mirrored repositories can be found on mirror.b10c.me