[Python-Dev] Mini-Pep: Simplifying the Integral ABC (original) (raw)

Guido van Rossum guido at python.org
Wed Jun 4 22:50:37 CEST 2008


On Wed, Jun 4, 2008 at 12:57 PM, Raymond Hettinger <python at rcn.com> wrote:

From: "Guido van Rossum" <guido at python.org>

Unless more folks actually say they agree I don't want to go forward with this. There was quite a bit of discussion about PEP 3141 and it was accepted; striking this much from it with virtually no discussion seems wrong to me. Not sure how to generate more discussion. It seems self-evident that an abc with lots of abstract methods is inherently less usable and that bitwise operations go beyond the basic notion of "integeriness". Requiring all those methods to be defined makes it harder to write a compliant class.

In general it is good to require that more thought goes into the design and implementation of a class, so that less thought needs to go into using it.

Other than int/long, no currently existing type matches-up with Integral. Does anyone care about this?

Does "this" refer to "the Integral ABC" or "no type matches up with it" ?

If something like numpy's int8 eventually grows the required methods, it is worrysome that the numerator/denominator properties will be automatically supplied for fractions.py to accept as inputs eventhough int8's wrap-around behavior makes them entirely unsuitable.

I'm not sure what you mean. This is probably just my lack of imagination. Can you give a small code example where using an int8 with the fractions module would cause problems? The Fraction class appears to be calling index on its arguments, which would convert the int8 to a proper int (or long, in Python 2.6).

I don't know if this bothers anyone. It would seem that a consumer of an Integral can assume the existence of methods but nothing about whether the result is usable. That might not be a big deal except that numpy is t he only known use case.

Any integer type that performs arithmetic modulo some number is problematic. Perhaps a totally separate ABC needs to be defined for this purpose, one that doesn't inherit from Rational.

Hopefully, some discussion gets generated. But if no one cares, I'll happily drop it.

Have you asked the numpy folks?

If enough people care, we could easily create a BinaryInteger ABC that defines the bitwise operations.

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list