Message309304
Here's a concrete example, using gmpy2 [1], that exercises the code path you're proposing to remove. I had to cheat a bit, since the gmpy2 types *don't* (currently) buy in to the numbers ABC tower (though there's no good reason that they couldn't do so), so I registered them manually.
>>> import fractions, numbers
>>> import gmpy2
>>> x = gmpy2.mpq(2, 3)
>>> numbers.Rational.register(type(x))
<class 'mpq'>
>>> numbers.Integral.register(type(x.denominator))
<class 'mpz'>
>>> fractions.Fraction(x, x) # code path exercised here ...
Fraction(1, 1)
Note that the numerator and the denominator of the resulting `Fraction` object are still of type `mpz`.
It _would_ be possible to remove the check and always use `math.gcd`, but it would result in a behaviour change: for the above code, we'd get a `Fraction` whose numerator and denominator were both of actual type `int` instead of `mpz`. Whether that's a desirable behaviour change or not is another question ...
[1] https://gmpy2.readthedocs.io/en/latest/ |
|
Date |
User |
Action |
Args |
2017-12-31 20:23:32 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, gphemsley |
2017-12-31 20:23:32 | mark.dickinson | set | messageid: <1514751812.75.0.467229070634.issue32466@psf.upfronthosting.co.za> |
2017-12-31 20:23:32 | mark.dickinson | link | issue32466 messages |
2017-12-31 20:23:32 | mark.dickinson | create | |
|