Skip to content

Commit 93ebac7

Browse files
gh-92417: fractions, decimal: Improve docs for alternative constructor methods (GH-92421) (GH-92971)
Co-authored-by: Ezio Melotti <[email protected]> (cherry picked from commit 090df84) Co-authored-by: Alex Waygood <[email protected]>
1 parent ebf3f12 commit 93ebac7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Doc/library/decimal.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ Decimal objects
571571
>>> Decimal(321).exp()
572572
Decimal('2.561702493119680037517373933E+139')
573573

574-
.. method:: from_float(f)
574+
.. classmethod:: from_float(f)
575575

576-
Classmethod that converts a float to a decimal number, exactly.
576+
Alternative constructor that only accepts instances of :class:`float` or
577+
:class:`int`.
577578

578579
Note `Decimal.from_float(0.1)` is not the same as `Decimal('0.1')`.
579580
Since 0.1 is not exactly representable in binary floating point, the

Doc/library/fractions.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ another rational number, or from a string.
105105

106106
.. versionadded:: 3.8
107107

108-
.. method:: from_float(flt)
108+
.. classmethod:: from_float(flt)
109109

110-
This class method constructs a :class:`Fraction` representing the exact
111-
value of *flt*, which must be a :class:`float`. Beware that
110+
Alternative constructor which only accepts instances of
111+
:class:`float` or :class:`numbers.Integral`. Beware that
112112
``Fraction.from_float(0.3)`` is not the same value as ``Fraction(3, 10)``.
113113

114114
.. note::
@@ -117,10 +117,10 @@ another rational number, or from a string.
117117
:class:`Fraction` instance directly from a :class:`float`.
118118

119119

120-
.. method:: from_decimal(dec)
120+
.. classmethod:: from_decimal(dec)
121121

122-
This class method constructs a :class:`Fraction` representing the exact
123-
value of *dec*, which must be a :class:`decimal.Decimal` instance.
122+
Alternative constructor which only accepts instances of
123+
:class:`decimal.Decimal` or :class:`numbers.Integral`.
124124

125125
.. note::
126126

0 commit comments

Comments
 (0)