Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-122450: Indicate thatFraction
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
python-cla-botbot commentedJul 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@@ -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. |
skirpichevJul 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
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.
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 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 theFraction
constructor, not thedenominator
property.
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 also agree. It's as if we requiredenomintor to be positive (as an argument) which is not the case. So I suggest to revert this PR.
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 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.
@serhiy-storchaka@skirpichev we discussed this at the sprint and decided that*denominator*
(italics) referred to the argument, butdenominator
(normal/roman) in the context of the sentence referred to the new argument. Regardless, it simplifies the arguments, so it is not always thedenominator
argument that is set as the class attribute.
A
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.
It says: "a new :class:Fraction
instance with value equal tonumerator/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.
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. |
IMO, alternative pr#122464 is in a better shape. |
Fraction
denominators are always positive.Fraction
denominators are always positive.Fraction
denominators are always positive@skirpichev I'm mentoring this contribution in the EuroPython sprints, I think it's a good first step improvement. A |
eb8ac4c
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@nacind for the PR, and@AA-Turner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…itive (pythonGH-136789)(cherry picked from commit eb8ac4c85773160a6104abafdea9159f26363a9b)Co-authored-by: nacind <107233139+nacind@users.noreply.github.com>
Sorry,@nacind and@AA-Turner, I could not cleanly backport this to
|
GH-136792 is a backport of this pull request to the3.14 branch. |
skirpichev commentedJul 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@AA-Turner, sorry. I don't think so. "with value equal to I would appreciate opinion of math's people ;-) CC@picnixz CC@serhiy-storchaka per experts index. |
…ways positive (python#136789)"This reverts commiteb8ac4c.
Uh oh!
There was an error while loading.Please reload this page.
In reference to#122450
Working on this at the EuroPython conference.
denominator
ofFraction
is positive, which should be documented #122450📚 Documentation preview 📚:https://cpython-previews--136789.org.readthedocs.build/