Fragment api changed...

sync with pysource.
Simplify pysource a little
This commit is contained in:
rocky
2020-08-23 19:27:52 -04:00
parent a5cfd81805
commit 71c17c4e53
2 changed files with 9 additions and 7 deletions

View File

@@ -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 == "<module>"
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
)

View File

@@ -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)