]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
don't identify the toplevel namespace by name #9997
authorBenjamin Peterson <benjamin@python.org>
Sat, 16 Oct 2010 03:45:45 +0000 (03:45 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 16 Oct 2010 03:45:45 +0000 (03:45 +0000)
Lib/test/test_scope.py
Misc/NEWS
Python/symtable.c

index 0e5a8e92b42a6aa2df6ef4972e8b7a59d506323a..390e39f79c05bfa6dec5fcf27325ec001b0e3e4d 100644 (file)
@@ -705,6 +705,14 @@ class ScopeTests(unittest.TestCase):
         h = g()
         self.assertEqual(h(), 3)
 
+    def testTopIsNotSignificant(self):
+        # See #9997.
+        def top(a):
+            pass
+        def b():
+            global a
+
+
 
 def test_main():
     run_unittest(ScopeTests)
index 80aa50f238219f4b69495739fe841b4dec6485b6..01a24427cc8a37714fca69da73233af33c84f5f4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1?
 Core and Builtins
 -----------------
 
+- Issue #9997: Don't let the name "top" have special significance in scope
+  resolution.
+
 - Issue #9862: Compensate for broken PIPE_BUF in AIX by hard coding
   its value as the default 512 when compiling on AIX.
 
index f75b9c997f495e3b491aba1c9436c381ef0adb8b..4a6c52335bb4564dd77f440717c45c143b2ff198 100644 (file)
@@ -924,7 +924,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
     st->st_cur = ste_new(st, name, block, ast, lineno, col_offset);
     if (st->st_cur == NULL)
         return 0;
-    if (name == GET_IDENTIFIER(top))
+    if (block == ModuleBlock)
         st->st_global = st->st_cur->ste_symbols;
     if (prev) {
         if (PyList_Append(prev->ste_children,