-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Support PEP 515 for Fraction's initialization from string #88424
Comments
Right now:
>>> from fractions import Fraction as F
>>> F(1_2_3, 3_2_1)
Fraction(41, 107) but >>> F('1_2_3/3_2_1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sk/src/cpython/Lib/fractions.py", line 115, in __new__
raise ValueError('Invalid literal for Fraction: %r' %
ValueError: Invalid literal for Fraction: '1_2_3/3_2_1'
or even this (should be consistent with int constructor, isn't?):
>>> F('1_2_3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sk/src/cpython/Lib/fractions.py", line 115, in __new__
raise ValueError('Invalid literal for Fraction: %r' %
ValueError: Invalid literal for Fraction: '1_2_3' Tentative patch attached. Let me know if this does make sense as a PR. |
+1 to the idea: So yes please to the PR. There should be tests that check that only the underscore rules allowed by |
On Fri, May 28, 2021 at 06:48:14AM +0000, Mark Dickinson wrote:
Ok, I did. In the initial version I catch int()'s exceptions to |
How about '1_/_2'? I think making / more separated adds value... though of course, someone will ask about '1 / 2' next. :-) |
I'd rather keep it consistent with the rules for int: that is, if I split on As for spaces around the |
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: