Two bugs and a refactor ..

1. parse2.py: try except in a loop with a (virtual) continue
   treat CONTINUE like JUMP_ABSOLUTE which it is
2. in taking methods off of constants, a parenthesis needs to be added

Some refactoring of global code done
This commit is contained in:
rocky
2017-12-03 10:46:22 -05:00
parent 0724dc1c0e
commit 5fe8303184
11 changed files with 116 additions and 66 deletions

View File

@@ -9,7 +9,9 @@ from uncompyle6.parsers.astnode import AST
from uncompyle6 import PYTHON3
from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.semantics.helper import print_docstring
from uncompyle6.semantics.helper import (
print_docstring, find_all_globals, find_globals, find_none
)
if PYTHON3:
from itertools import zip_longest
@@ -18,42 +20,6 @@ else:
from uncompyle6.show import maybe_show_ast_param_default
def find_all_globals(node, globs):
"""Find globals including LOAD_GLOBALs in this AST node."""
for n in node:
if isinstance(n, AST):
globs = find_all_globals(n, globs)
elif n.kind in frozenset(('STORE_GLOBAL', 'DELETE_GLOBAL', 'LOAD_GLOBAL')):
globs.add(n.pattr)
return globs
mkfunc_globals = frozenset(('STORE_GLOBAL', 'DELETE_GLOBAL', 'LOAD_GLOBAL'))
mklambda_globals = frozenset(('STORE_GLOBAL', 'DELETE_GLOBAL'))
def find_globals(node, globs, global_ops=mkfunc_globals):
"""Find globals in this statement."""
for n in node:
# print("XXX", n.kind, global_ops)
if isinstance(n, AST):
# FIXME: do I need a caser for n.kind="mkfunc"?
if n.kind in ("conditional_lambda", "return_lambda"):
globs = find_globals(n, globs, mklambda_globals)
else:
globs = find_globals(n, globs, global_ops)
elif n.kind in frozenset(global_ops):
globs.add(n.pattr)
return globs
def find_none(node):
for n in node:
if isinstance(n, AST):
if n not in ('return_stmt', 'return_if_stmt'):
if find_none(n):
return True
elif n.kind == 'LOAD_CONST' and n.pattr is None:
return True
return False
# FIXME: DRY the below code...
def make_function3_annotate(self, node, is_lambda, nested=1,