You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge branch 'master' into python-3.3-to-3.5
This commit is contained in:
@@ -265,6 +265,7 @@ class Scanner3(Scanner):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=None,
|
||||
)
|
||||
)
|
||||
for j in range(collection_start, i):
|
||||
@@ -278,6 +279,7 @@ class Scanner3(Scanner):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=insts[j].optype,
|
||||
)
|
||||
)
|
||||
new_tokens.append(
|
||||
@@ -290,6 +292,7 @@ class Scanner3(Scanner):
|
||||
has_arg=t.has_arg,
|
||||
has_extended_arg=False,
|
||||
opc=t.opc,
|
||||
optype=None,
|
||||
)
|
||||
)
|
||||
return new_tokens
|
||||
@@ -338,6 +341,7 @@ class Scanner3(Scanner):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=None,
|
||||
)
|
||||
)
|
||||
for j in range(collection_start, i, 2):
|
||||
@@ -363,6 +367,7 @@ class Scanner3(Scanner):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=insts[j + 1].optype,
|
||||
)
|
||||
)
|
||||
new_tokens.append(
|
||||
@@ -375,6 +380,7 @@ class Scanner3(Scanner):
|
||||
has_arg=t.has_arg,
|
||||
has_extended_arg=False,
|
||||
opc=t.opc,
|
||||
optype=t.optype,
|
||||
)
|
||||
)
|
||||
return new_tokens
|
||||
|
@@ -89,6 +89,7 @@ class Scanner37(Scanner37Base):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=None,
|
||||
)
|
||||
)
|
||||
for j in range(collection_start, i):
|
||||
@@ -102,6 +103,7 @@ class Scanner37(Scanner37Base):
|
||||
has_arg=True,
|
||||
has_extended_arg=False,
|
||||
opc=self.opc,
|
||||
optype=tokens[j].optype,
|
||||
)
|
||||
)
|
||||
new_tokens.append(
|
||||
|
@@ -352,6 +352,7 @@ class Scanner37Base(Scanner):
|
||||
has_arg=True,
|
||||
opc=self.opc,
|
||||
has_extended_arg=False,
|
||||
optype=inst.optype,
|
||||
),
|
||||
)
|
||||
jump_idx += 1
|
||||
@@ -423,6 +424,7 @@ class Scanner37Base(Scanner):
|
||||
has_arg=inst.has_arg,
|
||||
opc=self.opc,
|
||||
has_extended_arg=inst.has_extended_arg,
|
||||
optype=inst.optype,
|
||||
),
|
||||
)
|
||||
continue
|
||||
@@ -524,6 +526,7 @@ class Scanner37Base(Scanner):
|
||||
has_arg=inst.has_arg,
|
||||
opc=self.opc,
|
||||
has_extended_arg=inst.has_extended_arg,
|
||||
optype=inst.optype,
|
||||
),
|
||||
)
|
||||
pass
|
||||
|
@@ -66,11 +66,13 @@ class Token:
|
||||
has_arg=None,
|
||||
opc=None,
|
||||
has_extended_arg=False,
|
||||
optype=None,
|
||||
):
|
||||
self.kind = intern(opname)
|
||||
self.has_arg = has_arg
|
||||
self.attr = attr
|
||||
self.pattr = pattr
|
||||
self.optype = optype
|
||||
if has_extended_arg:
|
||||
self.offset = "%d_%d" % (offset, offset + 2)
|
||||
else:
|
||||
@@ -106,8 +108,8 @@ class Token:
|
||||
self.op = op
|
||||
|
||||
def __eq__(self, o):
|
||||
""" '==' on kind and "pattr" attributes.
|
||||
It is okay if offsets and linestarts are different"""
|
||||
"""'==' on kind and "pattr" attributes.
|
||||
It is okay if offsets and linestarts are different"""
|
||||
if isinstance(o, Token):
|
||||
return (self.kind == o.kind) and (
|
||||
(self.pattr == o.pattr) or self.attr == o.attr
|
||||
@@ -117,7 +119,7 @@ class Token:
|
||||
return self.kind == o
|
||||
|
||||
def __ne__(self, o):
|
||||
""" '!=', but it's okay if offsets and linestarts are different"""
|
||||
"""'!=', but it's okay if offsets and linestarts are different"""
|
||||
return not self.__eq__(o)
|
||||
|
||||
def __repr__(self):
|
||||
|
@@ -136,7 +136,7 @@ ASSIGN_DOC_STRING = lambda doc_string, doc_load: SyntaxTree(
|
||||
SyntaxTree(
|
||||
"expr", [Token(doc_load, pattr=doc_string, attr=doc_string)]
|
||||
),
|
||||
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__")]),
|
||||
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__", optype="name")]),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -148,10 +148,10 @@ NAME_MODULE = SyntaxTree(
|
||||
"assign",
|
||||
[
|
||||
SyntaxTree(
|
||||
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True)]
|
||||
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True, optype="name")]
|
||||
),
|
||||
SyntaxTree(
|
||||
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True)]
|
||||
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True, optype="name")]
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@@ -17,22 +17,21 @@ All the crazy things we have to do to handle Python functions in 3.6 and above.
|
||||
The saga of changes before 3.6 is in other files.
|
||||
"""
|
||||
from xdis import (
|
||||
iscode,
|
||||
CO_ASYNC_GENERATOR,
|
||||
CO_GENERATOR,
|
||||
code_has_star_arg,
|
||||
code_has_star_star_arg,
|
||||
CO_GENERATOR,
|
||||
CO_ASYNC_GENERATOR,
|
||||
iscode,
|
||||
)
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.semantics.helper import (
|
||||
find_all_globals,
|
||||
find_globals_and_nonlocals,
|
||||
find_none,
|
||||
)
|
||||
|
||||
from uncompyle6.show import maybe_show_tree_param_default
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
|
||||
|
||||
def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
@@ -55,7 +54,6 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
- handle format tuple parameters
|
||||
"""
|
||||
value = default
|
||||
maybe_show_tree_param_default(self.showast, name, value)
|
||||
if annotation:
|
||||
result = "%s: %s=%s" % (name, annotation, value)
|
||||
else:
|
||||
@@ -150,7 +148,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
kwonlyargcount = code.co_kwonlyargcount
|
||||
|
||||
paramnames = list(scanner_code.co_varnames[:argc])
|
||||
kwargs = list(scanner_code.co_varnames[argc: argc + kwonlyargcount])
|
||||
kwargs = list(scanner_code.co_varnames[argc : argc + kwonlyargcount])
|
||||
|
||||
paramnames.reverse()
|
||||
defparams.reverse()
|
||||
@@ -181,7 +179,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
)
|
||||
)
|
||||
|
||||
for param in paramnames[i + 1:]:
|
||||
for param in paramnames[i + 1 :]:
|
||||
if param in annotate_dict:
|
||||
params.append("%s: %s" % (param, annotate_dict[param]))
|
||||
else:
|
||||
|
@@ -240,10 +240,15 @@ class NonterminalActions:
|
||||
assert len(keys) == len(flat_elems) - 1
|
||||
for i, elem in enumerate(flat_elems[:-1]):
|
||||
assert elem.kind == "ADD_VALUE"
|
||||
try:
|
||||
value = "%r" % elem.pattr
|
||||
except Exception:
|
||||
value = elem.pattr
|
||||
if elem.optype in ("local", "name"):
|
||||
value = elem.attr
|
||||
elif elem.optype == "const" and not isinstance(elem.attr, str):
|
||||
value = elem.attr
|
||||
else:
|
||||
try:
|
||||
value = "%r" % elem.pattr
|
||||
except Exception:
|
||||
value = elem.pattr
|
||||
if elem.linestart is not None:
|
||||
if elem.linestart != self.line_number:
|
||||
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
|
||||
@@ -266,11 +271,14 @@ class NonterminalActions:
|
||||
for elem in flat_elems:
|
||||
if elem == "add_value":
|
||||
elem = elem[0]
|
||||
|
||||
if elem == "ADD_VALUE":
|
||||
if self.version < (3, 0, 0):
|
||||
value = "%r" % repr(elem.pattr)
|
||||
if elem.optype in ("local", "name"):
|
||||
value = elem.attr
|
||||
elif elem.optype == "const" and not isinstance(elem.attr, str):
|
||||
value = elem.attr
|
||||
else:
|
||||
value = "%s" % str(elem.pattr)
|
||||
value = "%s" % repr(elem.pattr)
|
||||
else:
|
||||
assert elem.kind == "ADD_VALUE_VAR"
|
||||
value = "%s" % elem.pattr
|
||||
|
Reference in New Issue
Block a user