summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_scope.py8
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/symtable.c2
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index ef56b88..5f8768a 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -693,6 +693,14 @@ result2 = h()
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)
diff --git a/Misc/NEWS b/Misc/NEWS
index bd9822b..95db8ed 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
- Issue #10006: type.__abstractmethods__ now raises an AttributeError. As a
result metaclasses can now be ABCs (see #9533).
+- Issue #9997: Don't let the name "top" have special significance in scope
+ resolution.
+
- Issue #9930: Remove bogus subtype check that was causing (e.g.)
float.__rdiv__(2.0, 3) to return NotImplemented instead of the
expected 1.5.
diff --git a/Python/symtable.c b/Python/symtable.c
index 0cbde7d..ab52abf 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -923,7 +923,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,