From 89d8cd943b25185e8d15b15636531ff84277bdab Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 26 Oct 2013 13:13:51 -0400 Subject: just return toplevel symbol table rather than all blocks (closes #19393) --- Lib/symtable.py | 5 +---- Misc/NEWS | 3 +++ Modules/symtablemodule.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/symtable.py b/Lib/symtable.py index 39c1a80..bb27196 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.values(): - 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 7e0291a..b450f35 100644 --- 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. diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c index 02a81f1..37df82d 100644 --- a/Modules/symtablemodule.c +++ b/Modules/symtablemodule.c @@ -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); -- cgit v0.12