From: Benjamin Peterson Date: Sat, 26 Oct 2013 17:13:51 +0000 (-0400) Subject: just return toplevel symbol table rather than all blocks (closes #19393) X-Git-Tag: v2.7.6rc1~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=657d06b13eb42dc300436cd1e1788c421a5ada9f;p=python just return toplevel symbol table rather than all blocks (closes #19393) --- diff --git a/Lib/symtable.py b/Lib/symtable.py index ca73f58651..0ba9d1af34 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -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: diff --git a/Misc/NEWS b/Misc/NEWS index b341c5b8fd..4a59b4b6a1 100644 --- 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 diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c index 15c0f92bf4..ed2bcc71d3 100644 --- a/Modules/symtablemodule.c +++ b/Modules/symtablemodule.c @@ -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);