python bug when subclassing list?
Hamish McKenzie
hamish at valvesoftware.com
Thu Nov 6 14:43:22 EST 2008
I want to write a Vector class and it makes the most sense to just subclass list. I also want to be able to instantiate a vector using either:
Vector( 1, 2, 3 )
OR
Vector( [1, 2, 3] )
so I have this:
class Vector(list):
def __new__( cls, *a ):
try:
print a
return list.__new__(cls, a)
except:
print 'broken'
return list.__new__(cls, list(a))
doing Vector( 1, 2, 3 ) on this class results in a TypeError - which doesn't seem to get caught by the try block (ie "broken" never gets printed, and it never tries to
I can do pretty much the exact same code but inheriting from tuple instead of list and it works fine.
is this a python bug? or am I doing something wrong?
thanks,
-h.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081106/9cc43035/attachment-0001.html>
More information about the Python-list
mailing list