New-style classes and special methods
Jp Calderone
exarkun at intarweb.us
Mon Feb 24 01:23:24 EST 2003
Consider this class:
class Foo:
def __getattr__(self, name):
return lambda arg: arg
It can be used thusly:
f = Foo()
print f[10]
Producing the output "10". Now consider this class:
class NewFoo(object):
def __getattr__(self, name):
return lambda arg: arg
When used in the same way, this exception is raised:
TypeError: unindexable object
From a quick glance at the source, it seems that neither tp_as_mapping nor
tp_as_sequence are being initialized, presumably because __getitem__ isn't
seen as being defined.
Is this analysis of the behavior correct? If so, what are the chances of
this being "fixed"?
Jp
--
A sad spectacle. If they be inhabited, what a scope for misery
and folly. If they be not inhabited, what a waste of space.
-- Thomas Carlyle, looking at the stars
--
up 15 days, 10:29, 7 users, load average: 0.00, 0.00, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030224/b56fc5b2/attachment.sig>
More information about the Python-list
mailing list