__delitem__ "feature"
Christian Heimes
lists at cheimes.de
Sun Dec 26 13:30:23 EST 2010
Am 26.12.2010 18:53, schrieb kj:
> It means that, for both subclasses, del fails to trigger the
> dynamically installed instance method __delitem__.
Magic methods like __delitem__ are looked up on the type, not on the
instance. You can't change the behaviour on instances.
> If I replace dict with UserDict, *both* deletion attempts lead to
> a call to the dynamic __delitem__ method, and are thus blocked.
> This is the behavior I expected of dict (and will help me hold on
> to my belief that I'm not going insane when inevitably I'm told
> that there's no bug in dict or list).
UserDict is an old style class (not a subclass of object). Old style
classes behave differently.
Christian
More information about the Python-list
mailing list