This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Implement the formatting part of PEP 515, '_' in numeric literals.
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Rosuav, brett.cannon, eric.smith, georg.brandl, ned.deily, python-dev
Priority: release blocker Keywords: patch

Created on 2016-05-21 20:38 by eric.smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
underscores_decimal_only.patch Rosuav, 2016-08-19 13:24 review
underscores_all_bases.patch Rosuav, 2016-08-19 13:34 review
underscores_with_tests.patch Rosuav, 2016-08-19 13:52 review
moar-tests.patch Rosuav, 2016-09-07 06:33 review
Messages (13)
msg266023 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-05-21 20:38
I've separated this out from issue 26331, so as to not interfere with discussions and code reviews for the parsing portion of the PEP.
msg273093 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-08-19 08:23
Unfortunately I'm not going to have time to implement this before 3.6 beta 1, so I'm un-assigning it to myself. I'll post to python-dev and hopefully someone else can get to it. Apologies for waiting so long.
msg273117 - (view) Author: Chris Angelico (Rosuav) * Date: 2016-08-19 13:24
Here's a first-cut patch. No docs, no tests, and applies only to decimal formatting. It involves redefining the thousands_separators flag from being a boolean to being a three-state flag (none, comma, or underscore), and (ab)uses LT_*_LOCALE to carry that same information around.
msg273120 - (view) Author: Chris Angelico (Rosuav) * Date: 2016-08-19 13:34
Hmm, adding bin/oct/hex support didn't turn out that hard. Although it feels like this code is getting hackish. Definitely needs code review!
msg273123 - (view) Author: Chris Angelico (Rosuav) * Date: 2016-08-19 13:52
Hmm, strange. Comma formatting never seems to have had tests added. So I've added a couple of simple tests of comma formatting at the same time as adding underscore formatting tests. Also, test_long.py currently has a comment "# octal" preceding a bunch of tests of *binary* formatting, and no tests of octal. So I've added those too.

In any case, here's a patch with full functionality and tests.
msg274769 - (view) Author: Chris Angelico (Rosuav) * Date: 2016-09-07 06:33
Another couple of tests, per comments.
msg275150 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-08 20:48
Latest patch LGTM. If Georg isn't able to get to issue #26331 then I'll commit to tomorrow. Do you want me to commit yours on your behalf right after, Chris to make sure this hits b1?
msg275151 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-08 20:48
Actually, Chris doesn't have commit privileges so I just will. :)
msg275165 - (view) Author: Chris Angelico (Rosuav) * Date: 2016-09-08 21:28
Thanks Brett! Sounds like a plan.
msg275367 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-09 18:11
Since Brett is working on the parsing part, I'll work on this. I might take a stab at the documentation first, but in any event I'll commit it tonight.
msg275545 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-10 02:28
I just noticed that the patch doesn't handle 'X' (uppercase) correctly, while it does handle 'x' (lowercase). I'll fix that when I commit.
msg275549 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-10 03:07
New changeset 99abb731ea7a by Eric V. Smith in branch 'default':
Issue 27080: PEP 515: add '_' formatting option.
https://hg.python.org/cpython/rev/99abb731ea7a
msg275550 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-09-10 03:08
I also fixed the code so both '_' and ',' can't be specified, and added tests. The documentation is also updated.
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71267
2016-09-10 03:08:14eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg275550

stage: resolved
2016-09-10 03:07:00python-devsetnosy: + python-dev
messages: + msg275549
2016-09-10 02:28:00eric.smithsetmessages: + msg275545
2016-09-09 18:11:39eric.smithsetassignee: eric.smith
messages: + msg275367
2016-09-08 21:28:39brett.cannonsetpriority: normal -> release blocker
nosy: + ned.deily
2016-09-08 21:28:07Rosuavsetmessages: + msg275165
2016-09-08 20:48:39brett.cannonsetmessages: + msg275151
2016-09-08 20:48:16brett.cannonsetnosy: + brett.cannon
messages: + msg275150
2016-09-07 06:33:49Rosuavsetfiles: + moar-tests.patch

messages: + msg274769
2016-08-19 13:52:32Rosuavsetfiles: + underscores_with_tests.patch

messages: + msg273123
2016-08-19 13:34:11Rosuavsetfiles: + underscores_all_bases.patch

messages: + msg273120
2016-08-19 13:24:12Rosuavsetfiles: + underscores_decimal_only.patch
keywords: + patch
messages: + msg273117
2016-08-19 13:17:06Rosuavsetnosy: + Rosuav
2016-08-19 08:23:18eric.smithsetassignee: eric.smith -> (no value)
messages: + msg273093
versions: + Python 3.6
2016-05-21 20:39:00eric.smithsetnosy: + georg.brandl
2016-05-21 20:38:09eric.smithcreate