]> granicus.if.org Git - python/commitdiff
just return toplevel symbol table rather than all blocks (closes #19393)
authorBenjamin Peterson <benjamin@python.org>
Sat, 26 Oct 2013 17:13:51 +0000 (13:13 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sat, 26 Oct 2013 17:13:51 +0000 (13:13 -0400)
Lib/symtable.py
Misc/NEWS
Modules/symtablemodule.c

index ca73f586511257603cf310a79340f14ca0008de1..0ba9d1af34c7799860db8b0d1cce53da7dab11a0 100644 (file)
@@ -10,10 +10,7 @@ import weakref
 __all__ = ["symtable", "SymbolTable", "Class", "Function", "Symbol"]
 
 def symtable(code, filename, compile_type):
-    raw = _symtable.symtable(code, filename, compile_type)
-    for top in raw.itervalues():
-        if top.name == 'top':
-            break
+    top = _symtable.symtable(code, filename, compile_type)
     return _newSymbolTable(top, filename)
 
 class SymbolTableFactory:
index b341c5b8fda7bf4da89644673d7f2c5db31cf258..4a59b4b6a1264be99ab9f73bad739795e4674236 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #19393: Fix symtable.symtable function to not be confused when there are
+  functions or classes named "top".
+
 - Issue #19327: Fixed the working of regular expressions with too big charset.
 
 - Issue #19350: Increasing the test coverage of macurl2path. Patch by Colin
index 15c0f92bf416f1800b482028c07c95a05d8b4254..ed2bcc71d3866ed30111a91a99487916c148132a 100644 (file)
@@ -33,7 +33,7 @@ symtable_symtable(PyObject *self, PyObject *args)
     st = Py_SymtableString(str, filename, start);
     if (st == NULL)
         return NULL;
-    t = st->st_symbols;
+    t = (PyObject *)st->st_top;
     Py_INCREF(t);
     PyMem_Free((void *)st->st_future);
     PySymtable_Free(st);