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
Implement the formatting part of PEP 515, '_' in numeric literals. #71267
Comments
I've separated this out from bpo-26331, so as to not interfere with discussions and code reviews for the parsing portion of the PEP. |
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. |
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. |
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! |
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. |
Another couple of tests, per comments. |
Latest patch LGTM. If Georg isn't able to get to issue bpo-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? |
Actually, Chris doesn't have commit privileges so I just will. :) |
Thanks Brett! Sounds like a plan. |
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. |
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. |
New changeset 99abb731ea7a by Eric V. Smith in branch 'default': |
I also fixed the code so both '_' and ',' can't be specified, and added tests. The documentation is also updated. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: