-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
@@ -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. |
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 the Fraction
constructor, not the denominator
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 require denomintor 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, 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
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 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.
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 |
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 eb8ac4c) 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 the 3.14 branch. |
@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 commit eb8ac4c.
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/