[issue32466] Remove fractions._gcd()

Mark Dickinson report at bugs.python.org
Sun Dec 31 14:33:10 EST 2017


Mark Dickinson <dickinsm at gmail.com> added the comment:

> In what scenario would the numerator and denominator be numbers.Rational but not an integer or a fraction

But that's not the issue here. The issue here is having an instance of `numbers.Rational` whose numerator and denominator are not specifically of concrete type `int`: the test that (IIUC) you're proposing to remove is:

     if type(numerator) is int is type(denominator):
         [...]

Certainly I'd expect the numerator and denominator to be instances of `numbers.Integral`, but that's more general than being of exact type `int`.

The `numbers.Integral` and `numbers.Rational` ABCs are deliberately not tied to particular concrete classes. It would be perfectly possible (and reasonable) for someone to have a `MyFraction` class that behaves like a `Fraction`, and whose numerator and denominator are instances of some other concrete class `MyInteger` that behaves like an integer.

The branch in the code is necessary to support that situation, so we can't simply remove it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32466>
_______________________________________


More information about the Python-bugs-list mailing list