mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-44258: support PEP 515 for Fraction's initialization from string (GH-26422)
* bpo-44258: support PEP 515 for Fraction's initialization from string * regexps's version * A different regexps version, which doesn't suffer from catastrophic backtracking * revert denom -> den * strip "_" from the decimal str, add few tests * drop redundant tests * Add versionchanged & whatsnew entry * Amend Fraction constructor docs * Change .. versionchanged:...
This commit is contained in:
parent
afb2eed72b
commit
89e50ab36f
5 changed files with 85 additions and 11 deletions
|
@ -42,7 +42,8 @@ another rational number, or from a string.
|
|||
|
||||
where the optional ``sign`` may be either '+' or '-' and
|
||||
``numerator`` and ``denominator`` (if present) are strings of
|
||||
decimal digits. In addition, any string that represents a finite
|
||||
decimal digits (underscores may be used to delimit digits as with
|
||||
integral literals in code). In addition, any string that represents a finite
|
||||
value and is accepted by the :class:`float` constructor is also
|
||||
accepted by the :class:`Fraction` constructor. In either form the
|
||||
input string may also have leading and/or trailing whitespace.
|
||||
|
@ -89,6 +90,10 @@ another rational number, or from a string.
|
|||
and *denominator*. :func:`math.gcd` always return a :class:`int` type.
|
||||
Previously, the GCD type depended on *numerator* and *denominator*.
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
Underscores are now permitted when creating a :class:`Fraction` instance
|
||||
from a string, following :PEP:`515` rules.
|
||||
|
||||
.. attribute:: numerator
|
||||
|
||||
Numerator of the Fraction in lowest term.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue