You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
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:
@@ -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,
|
||||
|
Reference in New Issue
Block a user