[Python-ideas] Fix some special cases in Fractions?

Paul Moore p.f.moore at gmail.com
Thu Aug 30 09:36:30 EDT 2018


On Thu, 30 Aug 2018 at 14:06, Nicolas Rolin <nicolas.rolin at tiime.fr> wrote:

> I think you could take the implementation further and decide that any
> power of Fraction(1) is Fraction(1) and any positive power of Fraction(0)
> is Fraction(0).
> I woudn't be shocked that Fraction(1) ** 3.7 == Fraction(1) and
> Fraction(0) ** 3.7 == 0.
>

You could do lots of things. But are any of them useful enough to warrant
changing documented behaviour, breaking backward compatibility, and
introducing a much more complex rule on how the arguments to
Fraction.__pow__ affect the type of the return value?

At the moment, there are no known use cases for this change - beyond Neil's
statement that he'd "like" the values to be as he quoted (with no
justification given).


> However the implementation for Fraction(-1) seems a bit to "ad hoc", and
> break some expected behavior of the powers.
> For exemple in your code Fraction(-2) ** Fraction(2, 3) != Fraction(-1) **
> Fraction(2, 3) * Fraction(2) ** Fraction(2, 3), whereas floats respect this.
> You could change the code so that the property (a *b) ** c == a**c *b**c,
> but idk how hard it is.
>

This (what behaviour is "expected" and/or natural) is the sort of detail
that can't be answered without knowing use cases - both use cases for the
proposed behaviour *and* use cases that rely on the existing behaviour.

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180830/c2449e4a/attachment-0001.html>


More information about the Python-ideas mailing list