-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-122450: Fix docs to state denominator positivity of Fraction #122464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-122450: Fix docs to state denominator positivity of Fraction #122464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose "expressed in its lowest terms" rather than "in lowest terms" for clarity.
What do you think @skirpichev ?
@@ -121,12 +121,11 @@ another rational number, or from a string. | |||
|
|||
.. attribute:: numerator | |||
|
|||
Numerator of the Fraction in lowest term. | |||
Numerator of the Fraction in lowest terms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numerator of the Fraction in lowest terms. | |
Numerator of the Fraction, expressed in its lowest terms. |
|
||
.. attribute:: denominator | ||
|
||
Denominator of the Fraction in lowest term. | ||
|
||
Positive denominator of the Fraction in lowest terms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Positive denominator of the Fraction in lowest terms. | |
Positive denominator of the Fraction, expressed in its lowest terms. |
@@ -297,11 +297,13 @@ class Rational(Real): | |||
@property | |||
@abstractmethod | |||
def numerator(self): | |||
"""The numerator of a rational number in lowest terms.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""The numerator of a rational number in lowest terms.""" | |
"""The numerator of a rational number, expressed in its lowest terms.""" |
raise NotImplementedError | ||
|
||
@property | ||
@abstractmethod | ||
def denominator(self): | ||
"""The (positive) denominator of a rational number in lowest terms.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""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. |
denominator
ofFraction
is positive, which should be documented #122450📚 Documentation preview 📚: https://cpython-previews--122464.org.readthedocs.build/