diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-10-14 07:54:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 07:54:59 (GMT) |
commit | b52c7306ea4470f9d7548655c2a1b89a07ff5504 (patch) | |
tree | 9a2bf501c6107a4a25e5fceaa8102cbd013bc96a /Doc/library/fractions.rst | |
parent | 66b3922b97388c328c9bd8df050eef11c0261fae (diff) | |
download | cpython-b52c7306ea4470f9d7548655c2a1b89a07ff5504.zip cpython-b52c7306ea4470f9d7548655c2a1b89a07ff5504.tar.gz cpython-b52c7306ea4470f9d7548655c2a1b89a07ff5504.tar.bz2 |
gh-121797: Add class method Fraction.from_number() (GH-121800)
It is an alternative constructor which only accepts a single numeric argument.
Unlike to Fraction.from_float() and Fraction.from_decimal() it accepts any
real numbers supported by the standard constructor (int, float, Decimal,
Rational numbers, objects with as_integer_ratio()).
Unlike to the standard constructor, it does not accept strings.
Diffstat (limited to 'Doc/library/fractions.rst')
-rw-r--r-- | Doc/library/fractions.rst | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst index 2ee1549..fc7f9a6 100644 --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -166,6 +166,16 @@ another rational number, or from a string. instance. + .. classmethod:: from_number(number) + + Alternative constructor which only accepts instances of + :class:`numbers.Integral`, :class:`numbers.Rational`, + :class:`float` or :class:`decimal.Decimal`, and objects with + the :meth:`!as_integer_ratio` method, but not strings. + + .. versionadded:: 3.14 + + .. method:: limit_denominator(max_denominator=1000000) Finds and returns the closest :class:`Fraction` to ``self`` that has |