Skip to content

gh-122450: Indicate that Fraction denominators are always positive #136789

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

Merged
merged 1 commit into from
Jul 19, 2025

Conversation

nacind
Copy link
Contributor

@nacind nacind commented Jul 19, 2025

In reference to #122450
Working on this at the EuroPython conference.


📚 Documentation preview 📚: https://cpython-previews--136789.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Jul 19, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

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

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

@skirpichev skirpichev Jul 19, 2025

Choose a reason for hiding this comment

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

Sorry, I don't think it's an improvement.

Old sentence is clear: we return a rational number with value numerator/denominator.
But original numerator and denominator may have any sign, may be not integers, etc.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @skirpichev. We can leave "equals", but "where the denominator is positive" is incorrect or at least ambiguous. "Denominator" refers to the argument of the Fraction constructor, not the denominator property.

Copy link
Member

@picnixz picnixz Jul 19, 2025

Choose a reason for hiding this comment

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

I also agree. It's as if we require denomintor to be positive (as an argument) which is not the case. So I suggest to revert this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened pr to fix docstrings in Rational class: #136800 It's a accompanying pr to #122464, which fix sphinx docs (and stuck in review).

But maybe it's ok to combine both and include reversion of this pr? All that only affects docs and IMO - fine for backporting up to 3.13.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@serhiy-storchaka @skirpichev we discussed this at the sprint and decided that *denominator* (italics) referred to the argument, but denominator (normal/roman) in the context of the sentence referred to the new argument. Regardless, it simplifies the arguments, so it is not always the denominator argument that is set as the class attribute.

A

Copy link
Member

Choose a reason for hiding this comment

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

It says: "a new :class:Fraction instance with value equal to numerator/denominator". "denominator" refers to argument, not to the property. Otherwise this sentence does not make sense. Then you say that in "where the denominator is positive" "denominator" refers to something other. But it clearly refers to the same thing as in previous expression. Your interpretation requires interpreting the same word in two different ways simultaneously. Even if it makes sense, it is very unclear and confusing. And to me, it just looks wrong.

@skirpichev
Copy link
Contributor

I suggest closing this pr.

Instead, as explained in the issue thread, we could document numerator/denominator properties of in the Rational class, i.e. add docstrings. Class description already says they are in lowest terms and denominator is positive.

@skirpichev
Copy link
Contributor

IMO, alternative pr #122464 is in a better shape.

@AA-Turner AA-Turner changed the title gh-122450: Now indicates that the resulting denominator will always be positive. gh-122450: Indicate that Fraction denominators are always positive. Jul 19, 2025
@AA-Turner AA-Turner changed the title gh-122450: Indicate that Fraction denominators are always positive. gh-122450: Indicate that Fraction denominators are always positive Jul 19, 2025
@AA-Turner
Copy link
Member

@skirpichev I'm mentoring this contribution in the EuroPython sprints, I think it's a good first step improvement.

A

@AA-Turner AA-Turner added awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes and removed awaiting merge labels Jul 19, 2025
@AA-Turner AA-Turner merged commit eb8ac4c into python:main Jul 19, 2025
45 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Jul 19, 2025
@miss-islington-app
Copy link

Thanks @nacind for the PR, and @AA-Turner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 19, 2025
…itive (pythonGH-136789)

(cherry picked from commit eb8ac4c)

Co-authored-by: nacind <107233139+nacind@users.noreply.github.com>
@miss-islington-app
Copy link

Sorry, @nacind and @AA-Turner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker eb8ac4c85773160a6104abafdea9159f26363a9b 3.13

@bedevere-app
Copy link

bedevere-app bot commented Jul 19, 2025

GH-136792 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 19, 2025
@skirpichev
Copy link
Contributor

skirpichev commented Jul 19, 2025

@AA-Turner, sorry. I don't think so.

"with value equal to numerator/denominator where the denominator is positive" - here "the denominator" is denominator of the Fraction instance or a parameter in it's constructor?

I would appreciate opinion of math's people ;-) CC @picnixz CC @serhiy-storchaka per experts index.

skirpichev added a commit to skirpichev/cpython that referenced this pull request Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes skip news sprint
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants