[Python-Dev] Tightening up the specification for locals()

Maciej Fijalkowski fijall at gmail.com
Mon May 13 13:40:27 CEST 2013


On Sun, May 12, 2013 at 2:01 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Fri, 03 May 2013 12:43:41 +1000
> Steven D'Aprano <steve at pearwood.info> wrote:
>> On 03/05/13 11:29, Nick Coghlan wrote:
>> > An exchange in one of the enum threads prompted me to write down
>> > something I've occasionally thought about regarding locals(): it is
>> > currently severely underspecified, and I'd like to make the current
>> > CPython behaviour part of the language/library specification. (We
>> > recently found a bug in the interaction between the __prepare__ method
>> > and lexical closures that was indirectly related to this
>> > underspecification)
>>
>> Fixing the underspecification is good. Enshrining a limitation as the
>> one correct way, not so good.
>
> I have to say, I agree with Steven here. Mutating locals() is currently
> an implementation detail, and it should IMHO stay that way. Only
> reading a non-mutated locals() should be well-defined.
>
> Regards
>
> Antoine.

Like it or not, people rely on this behavior. I don't think CPython
(or PyPy) can actually afford to change it. If so, documenting it
sounds like a better idea than leaving it undocumented only known to
the "inner shrine"

Cheers,
fijal


More information about the Python-Dev mailing list