overriding __getitem__ for a subclass of dict
greg
greg at cosc.canterbury.ac.nz
Mon Nov 16 19:06:37 EST 2009
Christian Heimes wrote:
> Most magic methods are implemented as descriptors. Descriptors only
> looked up on the type to increase the performance of the interpreter and
> to simply the C API.
There's also a semantic problem. Since new-style
classes are also instances (of class 'type') and you
can create subclasses of 'type', if special methods
were looked up on instances, it would be ambiguous
whether an attribute '__getitem__' on a class was
meant to specify the behaviour of the [] operation
on its instances, or on the class itself.
This problem didn't arise with old-style classes,
because classes and instances were clearly separated
(i.e. old-style classes were not old-style instances).
--
Geg
More information about the Python-list
mailing list