Skip to content

Commit b266fbc

Browse files
skirpichevAA-Turnerserhiy-storchaka
authored
gh-122450: Expand documentation for Rational and Fraction (#136800)
Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 506542b commit b266fbc

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Doc/library/fractions.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
The :mod:`fractions` module provides support for rational number arithmetic.
1515

1616

17-
A Fraction instance can be constructed from a pair of integers, from
18-
another rational number, or from a string.
17+
A Fraction instance can be constructed from a pair of rational numbers, from
18+
a single number, or from a string.
1919

2020
.. index:: single: as_integer_ratio()
2121

@@ -25,8 +25,8 @@ another rational number, or from a string.
2525

2626
The first version requires that *numerator* and *denominator* are instances
2727
of :class:`numbers.Rational` and returns a new :class:`Fraction` instance
28-
with value equal to ``numerator/denominator`` where the denominator is positive.
29-
If *denominator* is ``0``, it raises a :exc:`ZeroDivisionError`.
28+
with a value equal to ``numerator/denominator``.
29+
If *denominator* is zero, it raises a :exc:`ZeroDivisionError`.
3030

3131
The second version requires that *number* is an instance of
3232
:class:`numbers.Rational` or has the :meth:`!as_integer_ratio` method
@@ -125,7 +125,8 @@ another rational number, or from a string.
125125

126126
.. attribute:: denominator
127127

128-
Denominator of the Fraction in lowest term.
128+
Denominator of the Fraction in lowest terms.
129+
Guaranteed to be positive.
129130

130131

131132
.. method:: as_integer_ratio()

Doc/library/numbers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ The numeric tower
6969

7070
.. attribute:: numerator
7171

72-
Abstract.
72+
Abstract. The numerator of this rational number.
7373

7474
.. attribute:: denominator
7575

76-
Abstract.
76+
Abstract. The denominator of this rational number.
7777

7878

7979
.. class:: Integral

Lib/numbers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,27 @@ def conjugate(self):
290290

291291

292292
class Rational(Real):
293-
""".numerator and .denominator should be in lowest terms."""
293+
"""To Real, Rational adds numerator and denominator properties.
294+
295+
The numerator and denominator values should be in lowest terms,
296+
with a positive denominator.
297+
"""
294298

295299
__slots__ = ()
296300

297301
@property
298302
@abstractmethod
299303
def numerator(self):
304+
"""The numerator of a rational number in lowest terms."""
300305
raise NotImplementedError
301306

302307
@property
303308
@abstractmethod
304309
def denominator(self):
310+
"""The denominator of a rational number in lowest terms.
311+
312+
This denominator should be positive.
313+
"""
305314
raise NotImplementedError
306315

307316
# Concrete implementation of Real's conversion to float.

0 commit comments

Comments
 (0)