Overriding a method at the instance level on a subclass of a builtin type

George Sakkis george.sakkis at gmail.com
Wed Dec 3 03:12:26 CET 2008

On Dec 2, 7:58 pm, "Zac Burns" <zac... at gmail.com> wrote:

> Sorry for the long subject.
> I'm trying to create a subclass dictionary that runs extra init code
> on the first __getitem__ call. However, the performance of __getitem__
> is quite important - so I'm trying in the subclassed __getitem__
> method to first run some code and then patch in the original dict
> method for the instance to avoid even the check to see if the init
> code has been run. Various recipes using instancemethod and the like
> have failed me.

For new-style classes, special methods are always looked up in the
class, not the instance, so you're out of luck there. What are you
trying to do? Perhaps there is a less magic solution to the general


More information about the Python-list mailing list