strange behavor....

Arnaud Delobelle arnodel at gmail.com
Tue Nov 16 09:12:52 EST 2010


Hrvoje Niksic <hniksic at xemacs.org> writes:

> 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.

But it doesn't make this assumption for locals().

-- 
Arnaud



More information about the Python-list mailing list