[New-bugs-announce] [issue44258] Support PEP 515 for Fraction's initialization from string

Sergey B Kirpichev report at bugs.python.org
Fri May 28 01:47:31 EDT 2021


New submission from Sergey B Kirpichev <skirpichev at gmail.com>:

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 <report at bugs.python.org>
<https://bugs.python.org/issue44258>
_______________________________________


More information about the New-bugs-announce mailing list