You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Underscores in numeric literals not supported in lib2to3. #74055
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:
assignee=Noneclosed_at=<Date2017-04-14.01:31:24.462>created_at=<Date2017-03-22.00:12:25.319>labels= ['3.7', 'type-bug', 'expert-2to3']
title='Underscores in numeric literals not supported in lib2to3.'updated_at=<Date2017-04-14.01:31:24.461>user='https://github.com/nevsan'
Python uses more strong rules for underscores in numerical literals. Underscores are acceptable between digits and between the base prefix and digit. For example the regular expression for hexadecimals is r'0[xX]?[\da-fA-F]+(?:[\da-fA-F]+)*[lL]?'.
Underscores also are acceptable in the exponent of float literals:
Exponent=r'[eE][-+]?\d+(?:_\d+)*'
nevsan commented on Mar 22, 2017
nevsanmannequin
MannequinAuthor
More actions
The existing regular expressions weren't actually strict enough as is, so I made them even more correct. In particular, we must have at least one digit following 0[xXbBoO] and must be before any underscores.
Activity
nevsan commentedon Mar 22, 2017
The following should work in Python 3.6
serhiy-storchaka commentedon Mar 22, 2017
Python uses more strong rules for underscores in numerical literals. Underscores are acceptable between digits and between the base prefix and digit. For example the regular expression for hexadecimals is r'0[xX]?[\da-fA-F]+(?:[\da-fA-F]+)*[lL]?'.
Underscores also are acceptable in the exponent of float literals:
nevsan commentedon Mar 22, 2017
The existing regular expressions weren't actually strict enough as is, so I made them even more correct. In particular, we must have at least one digit following
0[xXbBoO]and must be before any underscores.I have a small set of test cases to examine correctness of these regular expressions: https://gist.github.com/nevsan/7fc78dc61d309842406d67d6839b9861
birkenfeld commentedon Mar 22, 2017
This is not true (but your test file does the right thing).
nevsan commentedon Mar 22, 2017
Thanks, it seems I misspoke. Glad I tested it!
serhiy-storchaka commentedon Mar 22, 2017
I suggest to use my regular expression for haxadedecimals. Your regular expression starves from catastrophic backtracking. Compare two examples:
re.match(r'0[xX]?[\da-fA-F]+(?:[\da-fA-F]+)*[lL]?'+r'\b', '0x'+'0'*100+'z')
re.match(r'0xX+[lL]?'+r'\b', '0x'+'0'*100+'z')
nevsan commentedon Mar 23, 2017
Good point. Updated.
Mariatta commentedon Apr 13, 2017
New changeset 97a40b7 by Mariatta (Nevada Sanchez) in branch '3.6':
bpo-29869: Allow underscores in numeric literals in lib2to3. (GH-752)
97a40b7
Mariatta commentedon Apr 13, 2017
New changeset 84c2d75 by Mariatta in branch '3.6':
Revert "bpo-29869: Allow underscores in numeric literals in lib2to3. (GH-752)" (GH-1109)
84c2d75
Mariatta commentedon Apr 13, 2017
Nevada Sanchez, please create your PR against the master branch.
Once that is merged, we will backport it to the 3.6 branch.
Thanks :)
Mariatta commentedon Apr 13, 2017
New changeset a6e395d by Mariatta (Nevada Sanchez) in branch 'master':
bpo-29869: Allow underscores in numeric literals in lib2to3. (GH-1119)
a6e395d
Mariatta commentedon Apr 13, 2017
New changeset 2cdf087 by Mariatta in branch '3.6':
[3.6] bpo-29869: Allow underscores in numeric literals in lib2to3. (GH-1119) (GH-1122)
2cdf087
Mariatta commentedon Apr 14, 2017
New changeset 9476299 by Mariatta in branch 'master':
bpo-29869: Add Nevada Sanchez to Misc/ACKS (GH-1125)
9476299
Mariatta commentedon Apr 14, 2017
PR has been merged and backported to 3.6.
I also added Nevada Sanchez to Misc/ACKS.
Thanks all :)