Usefulness of subclassing builtin number types

Gerhard Häring gerhard.haering at gmx.de
Sun Dec 15 16:50:33 EST 2002


* Wojtek Walczak <gminick at hacker.pl> [2002-12-15 21:42 +0000]:
> Dnia Sun, 15 Dec 2002 17:54:28 +0100, Gerhard Häring napisa?(a):
> > I'd like to subclass some builtin number types, and int in particular.
> > And I want (of course) that this subclassing is 'sticky', so if I do a:
> >     x = MyInt(25)
> >     x *= 2
> > I want 'x' to stay of the class MyInt. I even can't think of any use
> > case right now where I'd *not* want this. The problem? Python doesn't do
> > this, instead it always returns ints.
> I got exactly the same problem at the momment. Subclassing works for
> dicts/arrays but won't work for ints.

What exactly did not work?

> I wasted a few hours working on 
> it, but without any concrete results :/ Anybody ? Any ideas ?

Post code and what you'd expect it to do.

Gerhard
-- 
Favourite database:             http://www.postgresql.org/
Favourite programming language: http://www.python.org/
Combine the two:                http://pypgsql.sf.net/




More information about the Python-list mailing list