]> 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 39c1a8014fca8f0a1e9ae44e2604bb8f3ce2d98a..bb271968a42a90c9df1ab778b9d402ae2c6a3377 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.values():
-        if top.name == 'top':
-            break
+    top = _symtable.symtable(code, filename, compile_type)
     return _newSymbolTable(top, filename)
 
 class SymbolTableFactory:
index 7e0291a363d02658122fa3c12c3aa709ab1cd7a8..b450f357ec02d2ff67ef20f420f852af94c20381 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #19393: Fix symtable.symtable function to not be confused when there are
+  functions or classes named "top".
+
 - Issue #19339: telnetlib module is now using time.monotonic() when available
   to compute timeout.
 
index 02a81f11dc3d5b095dbafa2f72192609d53d2089..37df82d8b0fc917234b37b8d104c063a30ad201c 100644 (file)
@@ -32,7 +32,7 @@ symtable_symtable(PyObject *self, PyObject *args)
     st = Py_SymtableString(str, filename, start);
     if (st == NULL)
         return NULL;
-    t = st->st_blocks;
+    t = (PyObject *)st->st_top;
     Py_INCREF(t);
     PyMem_Free((void *)st->st_future);
     PySymtable_Free(st);