A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-April/099638.html below:

[Python-Dev] Inconsistent nesting of scopes in exec(..., locals())

[Python-Dev] Inconsistent nesting of scopes in exec(..., locals()) [Python-Dev] Inconsistent nesting of scopes in exec(..., locals())Joachim B Haga jobh at broadpark.no
Fri Apr 23 15:41:55 CEST 2010
There seem to be an inconsistency in the handling of local scopes in
exec. Consider the following code, which raises NameError if the '#' is
removed from the second last line.


block = """
b = 'ok'
def f():
    print(b)    # raises NameError here
f()
"""
scope = locals()#.copy()
exec(block, globals(), scope)


The intermediate scope is searched for the variable name if the third
argument to exec() is locals(), but not if it is locals().copy().
Testing further, it looks like NameError is raised for any dict which 
is not identically equal to either globals() or locals().

This behaviour is quite unexpected, and I believe it qualifies as a 
bug. Tested with python 2.6.5 and 3.1.2.

-- 
Joachim B Haga

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4