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

Jonathan Fine jfine2358 at gmail.com
Thu Aug 30 07:03:26 EDT 2018


Hi Neil

Summary: You say something should be done. But by who? Perhaps the
should starts with you.

Warning: This has been written quickly, and might have rough edges. If
so, I apologise.

You wrote

> But I'm only asking for fractional powers of -1, 0, and 1.  Is that really a
> complex issue?

> You are right that the fractional power of -1 and 1 has multiple values, but
> the fractional power of zero has a unique value.

>> I'm not really sure a stdlib should even try do deal with that. If I want
>> to have a symbolic way of handling complex power of fractions, I should
>> import a specific math library whose specific job is to get this right (the
>> same way if you want to do matrix stuff you have to import numpy).

> That's how I use the fractions package.  If you look at my example code,
> that seems like the kind of problem Fraction should make it easy to work
> with.  And yet, there was a wrinkle where I had to calculate Fraction(-1) **
> Fraction(a, b).

Let's try to make the best of what we've got.

First, the docs for the fraction module could be improved. Here's the
page and it's history.

    https://docs.python.org/3/library/fractions.html
    https://github.com/python/cpython/commits/3.7/Doc/library/fractions.rst

Already, doing this will help users. In particular, for a different
approach, point them to

    https://www.sympy.org/en/index.html

Second, assume you're right, when you say

> [This sort of problem], Fraction should make it easy [...]

The problem is, Python development resources are finite. They should
be more, but they're not. It's hard to go from 'Fraction should' to
'<specific individuals> should'. Perhaps the best one can come up with
is the developers of fraction.py. Here's the page and history.

    https://github.com/python/cpython/blob/3.7/Lib/fractions.py
    https://github.com/python/cpython/commits/3.7/Lib/fractions.py

Third, there is a way to go from 'Fraction should' to a group of
persons. If you're correct, that 'Fraction should', then I'm happy to
say that it follows that 'the Python community should'.

Now, the Python community is vast. It's more than the core developers.
I'm a member. You're a member. Everyone participating on this list is
a member. It's got lots of resources.

You want this problem solved. You've got clear ideas what should be
done. You say it should be done. And you're a member of the Python
community, who 'should fix this problem'.

The module fractions.py is pure Python. You can fork it to develop
your own solution, written as it should be. You can use this solution
and share it with the community. And you can submit it as a pull
request, for inclusion in the standard library.

To summarise. You're part of the Python community, who you believe
should solve this problem. Please, as a member of the community,
accept some responsibility for do what you think should be done.

And finally, thank you for drawing to our attention this blemish in
the fractions module (or its documentation).

-- 
Jonathan


More information about the Python-ideas mailing list