[Python-bugs-list] [Bug #133147] exec doesn't work with nested scopes

noreply@sourceforge.net noreply@sourceforge.net
Mon, 19 Feb 2001 15:31:42 -0800


Bug #133147, was updated on 2001-Feb-19 13:53
Here is a current snapshot of the bug.

Project: Python
Category: Parser/Compiler
Status: Closed
Resolution: Wont Fix
Bug Group: None
Priority: 5
Submitted by: mpmak
Assigned to : jhylton
Summary: exec doesn't work with nested scopes

Details: 
With latest (CVS) version of python included example won't even compile.
I’ve get same effect with reduce and filer instead of map.

def demo(xyz):
	zyx = map(lambda x: str(x), xyz)
	g = {}
	l = {}
	exec codeObject in g, l


Follow-Ups:

Date: 2001-Feb-19 15:31
By: jhylton

Comment:
The problem has nothing to do with map, filter, or reduce.  Rather,
as the exception says, "exec or 'import *' makes name ambiguous in nested
scope".  Perhaps the message is obscure but it does mention
the culprits: nested scopes and exec.

The name str in the lambda is not defined in demo().  The compiler
can't tell if the exec is going to try something like exec "str=len" .  So
it complains rather than guessing what is meant.

Either replace the lambda or the exec and it will work, e.g.

zyx = [str(x) for x in xyz]

-------------------------------------------------------

Date: 2001-Feb-19 14:12
By: fdrake

Comment:
Yes; assigned to Jeremy since he can explain it or label it a real bug.
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=133147&group_id=5470