[Python-Dev] variable name resolution in exec is incorrect

Guido van Rossum guido at python.org
Thu May 27 01:44:02 CEST 2010


Let me quickly jump in before someone actually deletes the feature.
Nick Coghlan and Thomas Wouters had it right; there is still a use
case. Don't kill it -- documenting it better is of course fine.

It *might* be possible to add a closure to the definition of f in the
case where globals != locals, but I doubt that that would be worth it,
and there's probably some code out there that would actually break, so
I'd say this is not a priority.

--Guido

On Wed, May 26, 2010 at 4:33 PM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> On 27/05/2010 00:38, Greg Ewing wrote:
>>
>> Mark Dickinson wrote:
>>
>>>>>> code = """\
>>>
>>> ... y = 3
>>> ... def f():
>>> ... return y
>>> ... f()
>>> ... """
>>>
>>>>>> exec code in {} # works fine
>>>>>> exec code in {}, {} # dies with a NameError
>>
>> Seems to me the whole idea of being able to specify
>> separate global and local scopes for top-level code is
>> screwy in the first place. Are there any use cases for
>> it? Maybe the second scope argument to exec() should
>> be deprecated?
>>
> Sounds good to me, certainly ends the confusion over this undoubtedly
> unintuitive behaviour. :-)
>
> Michael
>
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/blog
>
> READ CAREFULLY. By accepting and reading this email you agree, on behalf of
> your employer, to release me from all obligations and waivers arising from
> any and all NON-NEGOTIATED agreements, licenses, terms-of-service,
> shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure,
> non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have
> entered into with your employer, its partners, licensors, agents and
> assigns, in perpetuity, without prejudice to my ongoing rights and
> privileges. You further represent that you have the authority to release me
> from any BOGUS AGREEMENTS on behalf of your employer.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list