gh-122450: Fix docs to state denominator positivity of Fraction#122464
gh-122450: Fix docs to state denominator positivity of Fraction#122464privet-kitty wants to merge 12 commits intopython:mainfrom
Conversation
skirpichev
left a comment
There was a problem hiding this comment.
There is some redundancy, as docs already says: "The Fraction class inherits from the abstract base class numbers.Rational, and implements all of the methods and operations from that class." and "The numerator and denominator values should be instances of Integral and should be in lowest terms with denominator positive." But I think it's ok.
On another hand, it seems that docstrings for above properties are missing. I think this can be added in this pr. Probably, we shouldn't be too verbose here and docstrings could be as:
>>> help(int.numerator)
Help on getset descriptor builtins.int.numerator:
numerator
the numerator of a rational number in lowest terms
>>> help(int.denominator)
Help on getset descriptor builtins.int.denominator:
denominator
the denominator of a rational number in lowest terms
>>>Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
@skirpichev Thanks for your review.
|
skirpichev
left a comment
There was a problem hiding this comment.
I think we should be more close to int docstrings.
CC @picnixz
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
picnixz
left a comment
There was a problem hiding this comment.
We can use a more imperative style like this. And yes we should match the docstring formulation of int, though I think we can add "(positive)" since for ints, the denominator is always "1".
There was a problem hiding this comment.
By the way, you could also add the docstring at the level of numbers.Rational.denominator rather than at the level of fractions.Fraction.denominator. Because the positivity of the denominator is for any subclass of Rational AFAIK (Fraction is a subclass of Rational)
Good point. numbers.Rational assumes a specific canonical form for numerator/denominator (not just being positive). |
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
@picnixz @skirpichev Thanks. I reflected the suggestions and added docstrings to numerator and denominator of Rational |
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
@skirpichev thanks, reflected |
StanFromIreland
left a comment
There was a problem hiding this comment.
I propose "expressed in its lowest terms" rather than "in lowest terms" for clarity.
What do you think @skirpichev ?
| .. attribute:: numerator | ||
|
|
||
| Numerator of the Fraction in lowest term. | ||
| Numerator of the Fraction in lowest terms. |
There was a problem hiding this comment.
| Numerator of the Fraction in lowest terms. | |
| Numerator of the Fraction, expressed in its lowest terms. |
|
|
||
| Denominator of the Fraction in lowest term. | ||
|
|
||
| Positive denominator of the Fraction in lowest terms. |
There was a problem hiding this comment.
| Positive denominator of the Fraction in lowest terms. | |
| Positive denominator of the Fraction, expressed in its lowest terms. |
| @property | ||
| @abstractmethod | ||
| def numerator(self): | ||
| """The numerator of a rational number in lowest terms.""" |
There was a problem hiding this comment.
| """The numerator of a rational number in lowest terms.""" | |
| """The numerator of a rational number, expressed in its lowest terms.""" |
| @property | ||
| @abstractmethod | ||
| def denominator(self): | ||
| """The (positive) denominator of a rational number in lowest terms.""" |
There was a problem hiding this comment.
| """The (positive) denominator of a rational number in lowest terms.""" | |
| """The (positive) denominator of a rational number, expressed in its lowest terms.""" |
I think current wording is fine. |
| .. attribute:: numerator | ||
|
|
||
| Numerator of the Fraction in lowest term. | ||
| Numerator of the Fraction in lowest terms. |
There was a problem hiding this comment.
In fact, we say that "The Fraction class inherits from the abstract base class numbers.Rational, and implements all of the methods and operations from that class."
So, we could move these numerator/denominator descriptions to the Rational class.
CC @AA-Turner
There was a problem hiding this comment.
That would be worse; it requires people to look in two places to find out what happens with Fraction. Happy to improve in both places, but we shouldn't remove from here.
There was a problem hiding this comment.
This pr continued in #136800. I hope, I'll address review quickly;-)
but we shouldn't remove from here.
I'm not sure if it worth verbosity. I don't see e.g. where described real/imag properties for builtin types, except for the numbers module.
There was a problem hiding this comment.
I think so. I tried to attribute this work in a follow-up pr.
|
Closing: see #136800. A |
denominatorofFractionis positive, which should be documented #122450📚 Documentation preview 📚: https://cpython-previews--122464.org.readthedocs.build/