Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 230b206

Browse files
committed
don't identify the toplevel namespace by name #9997
1 parent 294a9fc commit 230b206

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_scope.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,14 @@ def h():
705705
h = g()
706706
self.assertEqual(h(), 3)
707707

708+
def testTopIsNotSignificant(self):
709+
# See #9997.
710+
def top(a):
711+
pass
712+
def b():
713+
global a
714+
715+
708716

709717
def test_main():
710718
run_unittest(ScopeTests)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9997: Don't let the name "top" have special significance in scope
14+
resolution.
15+
1316
- Issue #9862: Compensate for broken PIPE_BUF in AIX by hard coding
1417
its value as the default 512 when compiling on AIX.
1518

Python/symtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
924924
st->st_cur = ste_new(st, name, block, ast, lineno, col_offset);
925925
if (st->st_cur == NULL)
926926
return 0;
927-
if (name == GET_IDENTIFIER(top))
927+
if (block == ModuleBlock)
928928
st->st_global = st->st_cur->ste_symbols;
929929
if (prev) {
930930
if (PyList_Append(prev->ste_children,

0 commit comments

Comments
 (0)