]> granicus.if.org Git - python/commitdiff
Merged revisions 85562 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 16 Oct 2010 03:51:38 +0000 (03:51 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 16 Oct 2010 03:51:38 +0000 (03:51 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85562 | benjamin.peterson | 2010-10-15 22:45:45 -0500 (Fri, 15 Oct 2010) | 1 line

  don't identify the toplevel namespace by name #9997
........

Lib/test/test_scope.py
Misc/NEWS
Python/symtable.c

index b1549ef43ebf43660da22d38aef87a08acb1686f..ab9e812a98f68b244b27c25321c0d06bde2456d3 100644 (file)
@@ -647,6 +647,13 @@ result2 = h()
         self.assertEqual(2, global_ns["result2"])
         self.assertEqual(9, global_ns["result9"])
 
+    def testTopIsNotSignificant(self):
+        # See #9997.
+        def top(a):
+            pass
+        def b():
+            global a
+
 
 def test_main():
     with check_warnings(("import \* only allowed at module level",
index d8f2f1b3d62e32f2675dfe51a8f1df131ed565b0..c2b674b24527add65af5d3da9be2d1e18504f080 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.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 98d1e11564f54cf9988ae802a6baaec41a423d33..c18b39ecf15d2120b6b61ec11778a078c2645884 100644 (file)
@@ -847,7 +847,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
     st->st_cur = ste_new(st, name, block, ast, lineno);
     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,