[Python-checkins] gh-92417: `fractions`, `decimal`: Improve docs for alternative constructor methods (GH-92421) (GH-92970)

ambv webhook-mailer at python.org
Thu May 19 11:45:22 EDT 2022


https://github.com/python/cpython/commit/02fe22576ece289c299a4ae895cf912b29d15476
commit: 02fe22576ece289c299a4ae895cf912b29d15476
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022-05-19T17:45:12+02:00
summary:

gh-92417: `fractions`, `decimal`: Improve docs for alternative constructor methods (GH-92421) (GH-92970)

Co-authored-by: Ezio Melotti <ezio.melotti at gmail.com>
(cherry picked from commit 090df844ea16af3a5df79aba2b9c89ac6a31ba06)

Co-authored-by: Alex Waygood <Alex.Waygood at Gmail.com>

files:
M Doc/library/decimal.rst
M Doc/library/fractions.rst

diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst
index 2ad84f20b5560..d052581c97012 100644
--- a/Doc/library/decimal.rst
+++ b/Doc/library/decimal.rst
@@ -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
diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst
index c893f2d5389d5..5f0ecf1f135ea 100644
--- a/Doc/library/fractions.rst
+++ b/Doc/library/fractions.rst
@@ -114,10 +114,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::
@@ -126,10 +126,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::
 



More information about the Python-checkins mailing list