[Python-bugs-list] [ python-Bugs-528020 ] bug in Python2.2 in the nested scoping

noreply@sourceforge.net noreply@sourceforge.net
Tue, 12 Mar 2002 15:04:24 -0800


Bugs item #528020, was opened at 2002-03-10 05:37
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=528020&group_id=5470

Category: None
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Alex A. Naanou (alex_nanou)
Assigned to: Jeremy Hylton (jhylton)
Summary: bug in Python2.2 in the nested scoping

Initial Comment:
Hello!
  There appears to be a bug in Python2.2 in the nested 
scoping.
Example:

"""
#the definition:
def a():
  x = 0
  i = lambda: eval('x')
  return i()

#the return of the above (on several machines, 
versions & systems):
>>> a()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in a
  File "<stdin>", line 3, in <lambda>
  File "<string>", line 0, in ?
NameError: name 'x' is not defined
"""

and if I may, I have a remark in relation to the 
bove, there appear to be (in this particular case) an 
inconsistence between the lambda locals and globals,
as I understand, in the current state of development
the globals contain a 'unified' namespace with all the 
variables 'above' the nested block, but that does not 
appear to be the case! in the example above the lambda 
has no locals (as expected), and its globals DO NOT!! 
contain the namespace of the function 'a'..
I for one, can not understand this behaveur. 

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

>Comment By: Jeremy Hylton (jhylton)
Date: 2002-03-12 23:04

Message:
Logged In: YES 
user_id=31392

This looks like its the same as the bug report I just
closed.  The explanation is certainly the same.  Read
A.3.2.  eval() does not have access to names boudning in
enclosing scopes -- just locals and globals.


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

Comment By: Tim Peters (tim_one)
Date: 2002-03-10 09:10

Message:
Logged In: YES 
user_id=31435

Sorry, I don't see any bugs here.  Your understanding of 
globals in Python is way too elaborate -- the globals 
belong to the module level, and the only thing a nested 
scope can do to a global is mask/hide one by introducing a 
local of the same name.  There's no such thing as 
a "unified namespace" in Python.

I suggest you study the "4.1 Code blocks, execution frames, 
and namespaces" section of the Reference Manual, ask 
questions if needed on comp.lang.python, then come back 
here if you still think there's a bug.

Assigning to Jeremy in anticipation <wink>.

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=528020&group_id=5470