Skip to content

gh-122450: Expand documentation for Rational and Fraction #136800

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 10 commits into
base: main
Choose a base branch
from

Conversation

skirpichev
Copy link
Contributor

@skirpichev skirpichev commented Jul 19, 2025

@skirpichev skirpichev changed the title gh-122450: Expand numbers.Rational docstrings gh-122450: Expand numbers.Rational docstrings and sphinx docs Jul 19, 2025
@skirpichev skirpichev added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 19, 2025
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Look also at the paragraph before the constructor description: "A Fraction instance can be constructed from a pair of integers, from another rational number, or from a string." It is outdated. The numbers in the pair can be not only integers, and the single numerical argument can be not only rational. Making it more precise will only lead to repetition, so I would make it more generic instead.

Comment on lines 26 to +29
The first version requires that *numerator* and *denominator* are instances
of :class:`numbers.Rational` and returns a new :class:`Fraction` instance
with value equal to ``numerator/denominator`` where the denominator is positive.
If *denominator* is ``0``, it raises a :exc:`ZeroDivisionError`.
with value equal to ``numerator/denominator``. If *denominator* is zero, it
raises a :exc:`ZeroDivisionError`.
Copy link
Member

Choose a reason for hiding this comment

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

I still think this is worse. We now loose information that the denominator is positive, and implicitly require the user to know that {Fraction,Rational}.denominator should be positive. We are able to guarantee here that the denominator is a non-zero positive integer, there's no reason why we can't say that.

How about:

... and returns a new :class:`Fraction` instance with a value equal
to ``numerator/denominator``. The numerator and denominator of this
instance will be in the lowest terms, and the denominator will be positive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now loose information that the denominator is positive, and implicitly require the user to know that {Fraction,Rational}.denominator should be positive.

No. I think that class constructor should describe it's construction, not attributes, right?

  1. This information will be present in descriptions of numerator/denominator attributes of the Fraction
  2. Or in Rational docs.

I would prefer (2) for less redundancy. But as you insist on restoring (1) - I'll do that.

@bedevere-app
Copy link

bedevere-app bot commented Jul 21, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@AA-Turner AA-Turner changed the title gh-122450: Expand numbers.Rational docstrings and sphinx docs gh-122450: Expand documentation for Rational and Fraction Jul 21, 2025
@skirpichev skirpichev requested a review from AA-Turner July 21, 2025 13:10
@skirpichev
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Jul 21, 2025

Thanks for making the requested changes!

@AA-Turner: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants