Skip to content

Commit 02fe225

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

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Doc/library/decimal.rst

+3-2
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ another rational number, or from a string.
114114

115115
.. versionadded:: 3.8
116116

117-
.. method:: from_float(flt)
117+
.. classmethod:: from_float(flt)
118118

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

123123
.. note::
@@ -126,10 +126,10 @@ another rational number, or from a string.
126126
:class:`Fraction` instance directly from a :class:`float`.
127127

128128

129-
.. method:: from_decimal(dec)
129+
.. classmethod:: from_decimal(dec)
130130

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

134134
.. note::
135135

0 commit comments

Comments
 (0)