-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-42914: pprint.pprint function displays integer with underscores #24864
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
bpo-42914: pprint.pprint function displays integer with underscores #24864
Conversation
af908b7
to
dd308b0
Compare
Lib/pprint.py
Outdated
|
||
if issubclass(typ, int) and r is int.__repr__: | ||
if self._underscore_numbers: | ||
return builtins.format(object, "_d"), True, False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use f"{object:_d}"
instead of format? That'll be less bytecode and thus faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses builtins.format()
according ericvsmith's review (#24864 (comment)): the builtins.format()
function was considered lightly better than f-string format.
Format documentation shows '%-format' is not the preferred way of formating. builtins.format()
and f-string format use the same Format Specification Mini-Language but there is not an official preference between them (or I did not find it in the documentation). Do you know if there is an official opinion about it? Should I ask on python-dev mailing list?
I'm ready to change to f-string format but I'm afraid another commiter has another opinion about this point and ask to revert it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f-strings would be best. I was commenting on the built-in format()
vs str.format()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation. :)
I committed a change to use f-string format.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
1a229e3
to
57ff2b7
Compare
I changed the default behavior to keep backward compatibility (requested by https://bugs.python.org/msg389205). |
I have made the requested changes; please review again |
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
BPO-42914 was not added to the What's New in pythonGH-24864. This includes it in the "Improved Modules" section. Automerge-Triggered-By: GH:gpshead (cherry picked from commit 4846ea9) Co-authored-by: Wm. Keith van der Meulen <[email protected]>
BPO-42914 was not added to the What's New in GH-24864. This includes it in the "Improved Modules" section. Automerge-Triggered-By: GH:gpshead (cherry picked from commit 4846ea9) Co-authored-by: Wm. Keith van der Meulen <[email protected]>
This PR implements the separation for big integers by
_
character for better readability forpprint.pprint()
andpprint.pformat()
. So 123456 is displayed as '1_234_56'.A new parameter (
underscore_numbers
) is added so this new behavior can be disabled.https://bugs.python.org/issue42914