-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Underscores in numeric literals not supported in lib2to3. #74055
Comments
The following should work in Python 3.6
|
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+)*' |
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 I have a small set of test cases to examine correctness of these regular expressions: https://gist.github.com/nevsan/7fc78dc61d309842406d67d6839b9861 |
This is not true (but your test file does the right thing). |
Thanks, it seems I misspoke. Glad I tested it! |
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') |
Good point. Updated. |
Nevada Sanchez, please create your PR against the master branch. Thanks :) |
PR has been merged and backported to 3.6. |
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: