[Python-3000] Possible Duck Typing Problem in Python 2.5?

hashcollision hashcollision at gmail.com
Sun Dec 9 22:21:25 CET 2007


>From http://ivory.idyll.org/blog/dec-07/conversions.html:

class X:
    internal = [5,6,7,8]
    def __getitem__(self, i):
        return self.internal[i]

x = X()

l = [1,2,3]
print l + x

fails with

TypeError: can only concatenate list (not "instance") to list

I tried:

class X(list):
 internal = [5, 6, 7, 8]
 def __getitem__(self, i):
  return self.internal[i]
 def __len__(self):
  return internal
 def __iter__(self):
  return internal.__iter__()

but this fails also.

IMHO, this is a problem. Is it? If so, I suggest that it be fixed in
python 3000.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20071209/96e9a9b0/attachment.htm 


More information about the Python-3000 mailing list