strange behavor....
Steve Holden
steve at holdenweb.com
Tue Nov 16 09:29:06 EST 2010
On 11/16/2010 9:12 AM, Arnaud Delobelle wrote:
> 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().
>
That's because it reserves the right to optimize local storage without
extending the mapping to allowing item setting.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list