strange behavor....

Hrvoje Niksic hniksic at xemacs.org
Tue Nov 16 04:03:44 EST 2010


mdw at distorted.org.uk (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