Confused about __prepare__

Chris Rebert clp2 at
Fri Apr 8 01:09:59 CEST 2011

On Thu, Apr 7, 2011 at 3:31 PM, andrew cooke <andrew at> wrote:
> In the code below I use __prepare__ to change the class dictionary so that a tuple is stored in __setitem__().  Since __getitem__() removes the tuple I wasn't expecting any problems, but it seems that __init__ is being retrieved via some other mechanism.  Why?

I suspect you're being bitten by

In particular: "implicit special method lookup generally also bypasses
the __getattribute__() method".

__init__() is a special method.
The default __getattribute__() implementation consults an object's __dict__.
type.__new__() presumably does an implicit special method lookup for
__init__() behind the scenes.

Hence, your custom __dict__ is bypassed.


More information about the Python-list mailing list