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.

Author Sergey.Kirpichev
Recipients Sergey.Kirpichev
Date 2021-05-28.05:47:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
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.
History
Date User Action Args
2021-05-28 05:47:31Sergey.Kirpichevsetrecipients: + Sergey.Kirpichev
2021-05-28 05:47:31Sergey.Kirpichevsetmessageid: <[email protected]>
2021-05-28 05:47:31Sergey.Kirpichevlinkissue44258 messages
2021-05-28 05:47:31Sergey.Kirpichevcreate