[issue43520] Make Fraction(string) handle non-ascii slashes

STINNER Victor report at bugs.python.org
Sat Mar 20 10:41:27 EDT 2021


STINNER Victor <vstinner at python.org> added the comment:

Usually, constructors try to accept format returned by repr(obj), or even str(obj). It's the case for Fraction:

>>> str(fractions.Fraction(1, 2))
'1/2'
>>> fractions.Fraction("1/2")
Fraction(1, 2)

It works as expected.

I dislike the idea of trying to handle more Unicode characters which "look like" "/", or characters like "⅔". It sounds like a can of worm, and I don't think that such feature belongs to the stdlib. You can easily write your helper function accepting string and returning a fraction.

If someone is motivated to accept more character, I would prefer to have an unified proposition covering all Python number types (int, float, Fraction, complex, etc.) and listing all characters. Maybe a PEP would make sense.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43520>
_______________________________________


More information about the Python-bugs-list mailing list