Open privet-kitty opened 1 month ago
This is not necessarily the case if the input is a rational (which could be a custom class where the denominator is not always positive):
@picnixz Thanks for the information. I didn't realize that.
So what is not true is actually the description of as_integer_ratio
? This is a bad news...
Nevermind, the online docs actually say that the denominator of a rational should be positive: https://docs.python.org/3/library/numbers.html#numbers.Rational.
So actually, we can indeed improve the docs by saying that the denominator is positive.
Thank you! I'll fix it.
This is not necessarily the case if the input is a rational (which could be a custom class where the denominator is not always positive):
No, it couldn't. But it seems you already realized that.
So actually, we can indeed improve the docs by saying that the denominator is positive.
I'm not sure it's a real improvement as the numbers module already documents that.
Never mind, it seems that docstrings for numerator/denominator are missing. That looks as an issue. I think we should add them (to be like int.numerator/denominator).
But it seems you already realized that.
Yes, it's just that I don't read the online docs, I usually read the docstring when I can (just because it's easier with an IDE...).
I'm not sure it's a real improvement as the numbers module already documents that.
Since it's in another module (and webpage) people might forget about it. I think it's worth the redundancy.
Documentation
This suggestion is to clarify the current behavior of the
fractions
module.The current implementation of
Fraction
reduces an input numerator and a denominator so that the latter is positive, which is implemented in the following places:https://github.com/python/cpython/blob/d27a53fc02a87e76066fc4e15ff1fff3922a482d/Lib/fractions.py#L299-L303
This behavior is partially documented in https://docs.python.org/3.14/library/fractions.html:
It says that a denominator returned by
as_integer_ratio
is positive, but doesn't mention to the sign of thedenominator
property. I think there should be no problem with making that explicit also in the explanation ofdenominator
.Linked PRs