[Python-Dev] bug or a feature?
Steve Holden
steve at holdenweb.com
Wed Jun 11 03:30:56 CEST 2008
Benjamin Peterson wrote:
> On Tue, Jun 10, 2008 at 8:10 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
>> What do you think about this code:
>>
>> class A:
>> locals()[42] = 98
>>
>> Seems people rely on it working. Do we consider it part of python
>> language? (Note that you cannot do the same with getattr/setattr which
>> checks if argument is a string)
>
> Seems like a bug to me, but I don't think there is much we can do
> about it short of making locals a custom dict which rejects none
> string keys.
>
>
Given that the documentation has for a long time said:
"""locals( )
Update and return a dictionary representing the current local symbol
table. Warning: The contents of this dictionary should not be modified;
changes may not affect the values of local variables used by the
interpreter. """
it would be hard for the people who have relied on this behavior to
complain if it stopped working. Basically retaining this behavior is
pandering to people who have ignored the language specification!
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-Dev
mailing list