[Python-3000] What is numbers.Integral used for?

Raymond Hettinger python at rcn.com
Tue Feb 12 03:58:27 CET 2008


During the discussion of PEP 3141, what use cases were envisioned for the Integral type?  Were there some examples of concrete implementations other than <type 'int'> or <type 'long'??

I'm asking because I'm unclear about what a class is stating about itself when it registers as Integral.  I'm not sure that most finite fields would fit into the structure since they all Integrals support logical operations, are convertible into ints via __index__, andy the must support all of the operations defined for Reals.

I looked at the reference for Scheme's numeric tower to find guidance, but it seemed that the notion expressed solely through the "integer?" predicate which behaves differently than our inheritance tower.  For example, the spec says (rational? 6/10) ==> #t and (integer? 8/4) ==> #t but in our current implementation Rational(8,4) is not Integral like it is for Scheme.

Also, Scheme seems apply implement the notions of Exact/Inexact much differently
than we do: "A number is exact if it was written as an exact constant or was derived from exact numbers using only exact operations."  So, while all integers are exact, some floats and decimal constants could also be exact.  This matches how exactness is used in the decimal module -- all constants start as exact and operations can return either exact or inexact (and the module signals when this occurs).  Our module says Integrals are Exact and makes no further assertions.


Raymond



More information about the Python-3000 mailing list