Skip to content

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

privet-kitty
Copy link

@privet-kitty privet-kitty commented Jul 30, 2024

@ghost
Copy link

ghost commented Jul 30, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Contributor

@skirpichev skirpichev left a 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

>>>

@privet-kitty
Copy link
Author

@skirpichev Thanks for your review.

  • Fix rst according to your suggestion
  • Add docstrings to numerator and denominator of Fraction

Copy link
Contributor

@skirpichev skirpichev left a 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

privet-kitty and others added 2 commits July 31, 2024 21:57
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Copy link
Member

@picnixz picnixz left a 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".

Copy link
Member

@picnixz picnixz left a 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)

@skirpichev
Copy link
Contributor

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

Good point. numbers.Rational assumes a specific canonical form for numerator/denominator (not just being positive).

privet-kitty and others added 3 commits August 1, 2024 23:06
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>
@privet-kitty
Copy link
Author

@picnixz @skirpichev Thanks. I reflected the suggestions and added docstrings to numerator and denominator of Rational

privet-kitty and others added 2 commits August 2, 2024 11:58
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@privet-kitty
Copy link
Author

@skirpichev thanks, reflected

Copy link
Contributor

@StanFromIreland StanFromIreland left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""The (positive) denominator of a rational number in lowest terms."""
"""The (positive) denominator of a rational number, expressed in its lowest terms."""

@skirpichev
Copy link
Contributor

I propose "expressed in its lowest terms" rather than "in lowest terms" for clarity.

I think current wording is fine.

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants