New submission from Sergey B Kirpichev <[email protected]>:
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.
----------
components: Library (Lib)
files: fractions-from-str.diff
keywords: patch
messages: 394633
nosy: Sergey.Kirpichev
priority: normal
severity: normal
status: open
title: Support PEP 515 for Fraction's initialization from string
versions: Python 3.11
Added file: https://bugs.python.org/file50069/fractions-from-str.diff
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44258>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com