wishlist Python3K: subclass ints

Moshe Zadka moshez at math.huji.ac.il
Thu Jun 8 21:52:51 EDT 2000


[Moshe]
> Actually, in the number case specifically, I'd go for the
> no-hierarchy-have-a-good-model-optimize-behind-the-covers strategy:

[Aahz]
> You have a point, but I do still think there should be some sort of
> virtual base class behind all numbers.  That way, it's at least clear
> what operations should be available in any number class.

No, you're missing my point. At the Python level, there should be a single
number type. Asking whether a number is integral is fundemantelly
different then asking whether it is even, and yet nobody advocates having
odd and even numbers seperate classes deriving from the same base class.
A number is a number is a number -- and should be a single type. This is
where "optimize behind the scenes" comes in: we should have a "number"
type, s.t., isinstance(1, number) as wel as isinstance(1.5, numer), is
true. However, current implementation details say that it
would be convinient implementation-wise if type(1)!=type(1.5) -- which is
fine, just say that type(number) is implementation dependant, and cannot
be relied upon.

--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list