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

@@ -1,4 +1,7 @@
import sys
from uncompyle6.parsers.astnode import AST
from uncompyle6 import PYTHON3
if PYTHON3:
minint = -sys.maxsize-1
@@ -7,6 +10,53 @@ else:
minint = -sys.maxint-1
maxint = sys.maxint
read_write_global_ops = frozenset(('STORE_GLOBAL', 'DELETE_GLOBAL', 'LOAD_GLOBAL'))
read_global_ops = frozenset(('STORE_GLOBAL', 'DELETE_GLOBAL'))
# FIXME: this and find_globals could be paramaterized with one of the
# above global ops
def find_all_globals(node, globs):
"""Search AST node to find variable names that are global."""
for n in node:
if isinstance(n, AST):
globs = find_all_globals(n, globs)
elif n.kind in read_write_global_ops:
globs.add(n.pattr)
return globs
def find_globals(node, globs):
"""search AST node to find variable names that need a 'global' added."""
for n in node:
if isinstance(n, AST):
globs = find_globals(n, globs)
elif n.kind in read_global_ops:
globs.add(n.pattr)
return globs
# 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
def print_docstring(self, indent, docstring):
try:
if docstring.find('"""') == -1: