[Pythonmac-SIG] Problem subclassing tuple in Python 2.3

James Pryor jimpryor at Princeton.EDU
Thu Aug 7 15:25:21 EDT 2003


In Python 2.3, there is no general difficulty with having tuples of Sets:

>>> from sets import Set
>>> t=tuple((Set([1]),Set([2])))
>>> print t

Returns, as you'd expect:
(Set([1]), Set([2]))


But now suppose I subclass tuple, and want to convert the arguments supplied
to the __init__ method into Sets. I'd expect this to work:

>>> class mytuple(tuple):
...     def __init__(self,arg):
...         z=[Set([i]) for i in arg]
...         tuple.__init__(self,tuple(z))

But when I try:

>>> m=mytuple([1,2])
>>> m

I get:
(1, 2)

instead of the expected:
(Set([1]), Set([2]))


Is this the expected behavior? If so, why? Is there a work-around?


_________________________________________________
James Pryor <jimpryor at princeton.edu>
Assoc Prof of Philosophy, Princeton University




More information about the Pythonmac-SIG mailing list