strange behavor....

Hrvoje Niksic hniksic at
Tue Nov 16 10:03:44 CET 2010

mdw at (Mark Wooding) writes:

>> So even if the globals() dictionary is custom, its __setitem__ method is
>> *not* called.
> Fascinating.  Thank you.

In case it's not obvious, that is because CPython assumes the type for
many of its internal or semi-internal structures, and calls the
appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C)
directly.  So python doesn't break the encapsulation of dict itself, it
just takes the liberty to assume that globals() is a non-subclassed
dict, at least as far as __setitem__ is concerned.

More information about the Python-list mailing list