overriding __getitem__ for a subclass of dict

Carl Banks pavlovevidence at gmail.com
Mon Nov 16 11:35:07 CET 2009

On Nov 15, 2:52 pm, Steve Howell <showel... at yahoo.com> wrote:
> Does anybody have any links that points to the rationale for ignoring
> instance definitions of __getitem__ when new-style classes are
> involved?  I assume it has something to do with performance or
> protecting us from our own mistakes?

"Not important enough to justify complexity of implementation."

I doubt they would have left if out of new-style classes if it had
been straightforward to implement (if for no other reason than to
retain backwards compatibility), but it wasn't.  The way attribute
lookups work meant it would have required all kinds of double lookups
and edge cases.  Some regarded it as dubious to begin with.  And it's
easily worked around by simply having __getitem__ call another method,
as you've seen.  Given all this it made better sense to just leave it
out of new-style classes.

Unfortunately not all such decisions and justifications are collected
in a tidy place.

Carl Banks

More information about the Python-list mailing list