diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index ea24c1cb..194fa80a 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -1931,7 +1931,7 @@ def code_deparse( co, out=StringIO(), version=None, - is_pypy=None, + is_pypy=IS_PYPY, debug_opts=DEFAULT_DEBUG_OPTS, code_objects={}, compile_mode="exec", @@ -1960,9 +1960,8 @@ def code_deparse( if version is None: version = sysinfo2float() - if is_pypy is None: - is_pypy = IS_PYPY + # store final output stream for case of error scanner = get_scanner(version, is_pypy=is_pypy) show_asm = debug_opts.get("asm", None) @@ -1989,14 +1988,17 @@ def code_deparse( is_pypy=is_pypy, ) - deparsed.ast = deparsed.build_ast(tokens, customize) + isTopLevel = co.co_name == "" + deparsed.ast = deparsed.build_ast(tokens, customize, co, isTopLevel=isTopLevel) assert deparsed.ast == "stmts", "Should have parsed grammar start" - del tokens # save memory + # save memory + del tokens # convert leading '__doc__ = "..." into doc string assert deparsed.ast == "stmts" + (deparsed.mod_globs, nonlocals) = pysource.find_globals_and_nonlocals( deparsed.ast, set(), set(), co, version ) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 04bc7379..c8b2a981 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -135,7 +135,7 @@ import sys IS_PYPY = "__pypy__" in sys.builtin_module_names PYTHON3 = sys.version_info >= (3, 0) -from xdis import iscode, COMPILER_FLAG_BIT +from xdis import iscode, COMPILER_FLAG_BIT, sysinfo2float from uncompyle6.parser import get_python_parser from uncompyle6.parsers.treenode import SyntaxTree @@ -2564,7 +2564,7 @@ def code_deparse( assert iscode(co) if version is None: - version = float(sys.version[0:3]) + version = sysinfo2float() # store final output stream for case of error scanner = get_scanner(version, is_pypy=is_pypy)