]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92417: `fractions`, `decimal`: Improve docs for alternative constructor methods...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 19 May 2022 15:45:30 +0000 (08:45 -0700)
committerGitHub <noreply@github.com>
Thu, 19 May 2022 15:45:30 +0000 (17:45 +0200)
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
(cherry picked from commit 090df844ea16af3a5df79aba2b9c89ac6a31ba06)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Doc/library/decimal.rst
Doc/library/fractions.rst

index e759c5cf23b9e74fe77d92f7211565d67e29c46f..47627c02561b941b93856af5c6eff6efe4d2c568 100644 (file)
@@ -571,9 +571,10 @@ Decimal objects
       >>> Decimal(321).exp()
       Decimal('2.561702493119680037517373933E+139')
 
-   .. method:: from_float(f)
+   .. classmethod:: from_float(f)
 
-      Classmethod that converts a float to a decimal number, exactly.
+      Alternative constructor that only accepts instances of :class:`float` or
+      :class:`int`.
 
       Note `Decimal.from_float(0.1)` is not the same as `Decimal('0.1')`.
       Since 0.1 is not exactly representable in binary floating point, the
index a4d006eb58ffeb487aba0d1688fa6911dceb4f74..0f7940ae68bef4f70ec7ffb4c65b663dea6552da 100644 (file)
@@ -105,10 +105,10 @@ another rational number, or from a string.
 
       .. versionadded:: 3.8
 
-   .. method:: from_float(flt)
+   .. classmethod:: from_float(flt)
 
-      This class method constructs a :class:`Fraction` representing the exact
-      value of *flt*, which must be a :class:`float`. Beware that
+      Alternative constructor which only accepts instances of
+      :class:`float` or :class:`numbers.Integral`. Beware that
       ``Fraction.from_float(0.3)`` is not the same value as ``Fraction(3, 10)``.
 
       .. note::
@@ -117,10 +117,10 @@ another rational number, or from a string.
          :class:`Fraction` instance directly from a :class:`float`.
 
 
-   .. method:: from_decimal(dec)
+   .. classmethod:: from_decimal(dec)
 
-      This class method constructs a :class:`Fraction` representing the exact
-      value of *dec*, which must be a :class:`decimal.Decimal` instance.
+      Alternative constructor which only accepts instances of
+      :class:`decimal.Decimal` or :class:`numbers.Integral`.
 
       .. note::