You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Sync 3.7+ n_call code with decompyle6
This commit is contained in:
@@ -21,7 +21,6 @@ SKIP_TESTS=(
|
|||||||
[test_context.py]=1
|
[test_context.py]=1
|
||||||
[test_coroutines.py]=1 # Parse error
|
[test_coroutines.py]=1 # Parse error
|
||||||
[test_codecs.py]=1
|
[test_codecs.py]=1
|
||||||
[test_code.py]=1 # Investigate
|
|
||||||
[test_complex.py]=1 # Investigate
|
[test_complex.py]=1 # Investigate
|
||||||
[test_crypt.py]=1 # Parse error
|
[test_crypt.py]=1 # Parse error
|
||||||
[test_ctypes.py]=1 # it fails on its own
|
[test_ctypes.py]=1 # it fails on its own
|
||||||
|
@@ -21,7 +21,6 @@ SKIP_TESTS=(
|
|||||||
[test_context.py]=1
|
[test_context.py]=1
|
||||||
[test_coroutines.py]=1 # Parse error
|
[test_coroutines.py]=1 # Parse error
|
||||||
[test_codecs.py]=1
|
[test_codecs.py]=1
|
||||||
[test_code.py]=1 # Investigate
|
|
||||||
[test_complex.py]=1 # Investigate
|
[test_complex.py]=1 # Investigate
|
||||||
[test_crypt.py]=1 # Parse error
|
[test_crypt.py]=1 # Parse error
|
||||||
[test_ctypes.py]=1 # it fails on its own
|
[test_ctypes.py]=1 # it fails on its own
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
"""Isolate Python 3.7 version-specific semantic actions here.
|
"""Isolate Python 3.7 version-specific semantic actions here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
from uncompyle6.semantics.consts import (
|
from uncompyle6.semantics.consts import (
|
||||||
PRECEDENCE,
|
PRECEDENCE,
|
||||||
TABLE_DIRECT,
|
TABLE_DIRECT,
|
||||||
@@ -155,6 +156,99 @@ def customize_for_version37(self, version):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def gen_function_parens_adjust(mapping_key, node):
|
||||||
|
"""If we can avoid the outer parenthesis
|
||||||
|
of a generator function, set the node key to
|
||||||
|
'call_generator' and the caller will do the default
|
||||||
|
action on that. Otherwise we do nothing.
|
||||||
|
"""
|
||||||
|
if mapping_key.kind != "CALL_FUNCTION_1":
|
||||||
|
return
|
||||||
|
|
||||||
|
args_node = node[-2]
|
||||||
|
if args_node == "pos_arg":
|
||||||
|
assert args_node[0] == "expr"
|
||||||
|
n = args_node[0][0]
|
||||||
|
if n == "generator_exp":
|
||||||
|
node.kind = "call_generator"
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
|
def n_call(node):
|
||||||
|
p = self.prec
|
||||||
|
self.prec = 100
|
||||||
|
mapping = self._get_mapping(node)
|
||||||
|
table = mapping[0]
|
||||||
|
key = node
|
||||||
|
for i in mapping[1:]:
|
||||||
|
key = key[i]
|
||||||
|
pass
|
||||||
|
opname = key.kind
|
||||||
|
if opname.startswith("CALL_FUNCTION_VAR_KW"):
|
||||||
|
# Python 3.5 changes the stack position of
|
||||||
|
# *args: kwargs come after *args whereas
|
||||||
|
# in earlier Pythons, *args is at the end
|
||||||
|
# which simplifies things from our
|
||||||
|
# perspective. Python 3.6+ replaces
|
||||||
|
# CALL_FUNCTION_VAR_KW with
|
||||||
|
# CALL_FUNCTION_EX We will just swap the
|
||||||
|
# order to make it look like earlier
|
||||||
|
# Python 3.
|
||||||
|
entry = table[key.kind]
|
||||||
|
kwarg_pos = entry[2][1]
|
||||||
|
args_pos = kwarg_pos - 1
|
||||||
|
# Put last node[args_pos] after subsequent kwargs
|
||||||
|
while node[kwarg_pos] == "kwarg" and kwarg_pos < len(node):
|
||||||
|
# swap node[args_pos] with node[kwargs_pos]
|
||||||
|
node[kwarg_pos], node[args_pos] = node[args_pos], node[kwarg_pos]
|
||||||
|
args_pos = kwarg_pos
|
||||||
|
kwarg_pos += 1
|
||||||
|
elif opname.startswith("CALL_FUNCTION_VAR"):
|
||||||
|
# CALL_FUNCTION_VAR's top element of the stack contains
|
||||||
|
# the variable argument list, then comes
|
||||||
|
# annotation args, then keyword args.
|
||||||
|
# In the most least-top-most stack entry, but position 1
|
||||||
|
# in node order, the positional args.
|
||||||
|
argc = node[-1].attr
|
||||||
|
nargs = argc & 0xFF
|
||||||
|
kwargs = (argc >> 8) & 0xFF
|
||||||
|
# FIXME: handle annotation args
|
||||||
|
if nargs > 0:
|
||||||
|
template = ("%c(%P, ", 0, (1, nargs + 1, ", ", 100))
|
||||||
|
else:
|
||||||
|
template = ("%c(", 0)
|
||||||
|
self.template_engine(template, node)
|
||||||
|
|
||||||
|
args_node = node[-2]
|
||||||
|
if args_node in ("pos_arg", "expr"):
|
||||||
|
args_node = args_node[0]
|
||||||
|
if args_node == "build_list_unpack":
|
||||||
|
template = ("*%P)", (0, len(args_node) - 1, ", *", 100))
|
||||||
|
self.template_engine(template, args_node)
|
||||||
|
else:
|
||||||
|
if len(node) - nargs > 3:
|
||||||
|
template = (
|
||||||
|
"*%c, %P)",
|
||||||
|
nargs + 1,
|
||||||
|
(nargs + kwargs + 1, -1, ", ", 100),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
template = ("*%c)", nargs + 1)
|
||||||
|
self.template_engine(template, node)
|
||||||
|
self.prec = p
|
||||||
|
self.prune()
|
||||||
|
elif opname.startswith("CALL_FUNCTION_1") and not re.match("\d", opname[-1]):
|
||||||
|
self.template_engine(("%c(%c)", (0, "expr"), 1), node)
|
||||||
|
self.prec = p
|
||||||
|
self.prune()
|
||||||
|
else:
|
||||||
|
gen_function_parens_adjust(key, node)
|
||||||
|
|
||||||
|
self.prec = p
|
||||||
|
self.default(node)
|
||||||
|
|
||||||
|
self.n_call = n_call
|
||||||
|
|
||||||
def n_importlist37(node):
|
def n_importlist37(node):
|
||||||
if len(node) == 1:
|
if len(node) == 1:
|
||||||
self.default(node)
|
self.default(node)
|
||||||
|
Reference in New Issue
Block a user