Usefulness of subclassing builtin number types

Wojtek Walczak gminick at hacker.pl
Sun Dec 15 16:42:53 EST 2002


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. I wasted a few hours working on 
it, but without any concrete results :/ Anybody ? Any ideas ?

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list