wishlist Python3K: subclass ints
Moshe Zadka
moshez at math.huji.ac.il
Thu Jun 8 15:56:46 EDT 2000
On 8 Jun 2000, Aahz Maruch wrote:
> In article <393FD0C7.D70479A2 at visionart.com>,
> Pete Shinners <pete at visionart.com> wrote:
> >
> > - Also gone are all the nit-picking type checking routines.
> > instead of first checking if a variable is a "class" type,
> > then checking if the object is a certain class, all variables
> > hold objects of the same "rank". the best move would be to
> > have "int" and "float" be subclassed from a base class like
> > "realnumber".
>
> Close, but no cigar. Start with the base class "number". Then
> everything else follows: int, float, rational, complex.
Actually, in the number case specifically, I'd go for the
no-hierarchy-have-a-good-model-optimize-behind-the-covers strategy:
an int is a rational is a complex, any number might be exact or inexact.
Inexact is implemented internally as floating-point, of course, but it's
quite a good warning to users.
Note that a really crazy extension might have non-rational exact real
numbers (e.g., constructive reals), and it's a difficult question of how
to integrate it. Lucky for us, Python is a New Jersey language, so we can
just ignore the question.
--
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