Closed
Description
Bug description:
The fractions.Fraction()
error message differs when, for example, 123.dd
is done instead of 123.aa
; they should be equal.
>>> from fractions import Fraction >>> Fraction("123.dd") Traceback (most recent call last): File "<stdin>", line 1, in <module> Fraction("123.dd") File "C:\Program Files\Python313\Lib\fractions.py", line 251, in __new__ numerator = numerator * scale + int(decimal) ^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: 'dd' >>> Fraction("123.aa") Traceback (most recent call last): File "<stdin>", line 1, in <module> Fraction("123.aa") File "C:\Program Files\Python313\Lib\fractions.py", line 239, in __new__ raise ValueError('Invalid literal for Fraction: %r' % ValueError: Invalid literal for Fraction: '123.aa'
I discovered this bug while inspecting the rational parsing regex.
Lines 57 to 69 in dac1da2
I think the bug stems from line 65's matching of
d*
instead of \d*
. CPython versions tested on:
3.13
Operating systems tested on:
Windows