[Python-bugs-list] [ python-Bugs-463640 ] weird namespace phenomenon
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 21 Sep 2001 11:26:49 -0700
Bugs item #463640, was opened at 2001-09-21 11:26
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=463640&group_id=5470
Category: Python Interpreter Core
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: weird namespace phenomenon
Initial Comment:
# == module f.py
y = 10
def g():
if y:
y = 100
return y
# == module h.py
import f
print f.g()
# == plop these two modules into the same directory
and 'cd' to that directory.
When you run 'python h.py' at the command line, line 6
of f.py (if y:)
creates a problem due to f being supposedly undefined.
The error is
registered as NameError or UnboundLocalError depending
on what version
of the python core you're running. Python 2.1.x says
y is being
referenced before assignment, yet if you change the
_next_ line to read
"z = 100" rather than "y = 100", the whole thing runs
fine, printing 10
(the value of f.y) at the end as expected.
This is at the very least an extreme logic quirk in
how python namespaces
work, and at worst a bug badly in need of correction
(since vsn 1.5.2 or
before).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=463640&group_id=5470