mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-26 22:50:40 +00:00
Fix bug in 3.6 handling kwonly params ...
when there are annotation args
This commit is contained in:
parent
5616f56442
commit
5c31fdc362
BIN
test/bytecode_3.6_run/05_call_function_kw2.pyc
Normal file
BIN
test/bytecode_3.6_run/05_call_function_kw2.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7_run/05_call_function_kw2.pyc
Normal file
BIN
test/bytecode_3.7_run/05_call_function_kw2.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.8_run/05_call_function_kw2.pyc
Normal file
BIN
test/bytecode_3.8_run/05_call_function_kw2.pyc
Normal file
Binary file not shown.
@ -59,3 +59,14 @@ assert p == Point(**dict(x=11, y=22))
|
||||
def posonly_sum(pos_arg1, *arg, **kwarg):
|
||||
return pos_arg1 + sum(arg) + sum(kwarg.values())
|
||||
assert 1+2+3+4 == posonly_sum(1,*(2,3),**{"4":4})
|
||||
|
||||
# From 3.7 test_grammar.py
|
||||
# Bug was in handling keyword-only parameters when there are annotations.
|
||||
# The stack order from least- to most-recent is:
|
||||
# default, keyword, annotation, closure
|
||||
# This changes in between Python 3.5 and 3.6.
|
||||
def f(a, b: 1, c: 2, d, e: 3=4, f=5, *g: 6, h: 7, i=8, j: 9=10,
|
||||
**k: 11) -> 12: pass
|
||||
|
||||
assert f.__annotations__ == {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
|
||||
'k': 11, 'return': 12}
|
||||
|
@ -92,38 +92,40 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
else:
|
||||
pos_args, kw_args, annotate_argc, closure = args_attr
|
||||
|
||||
i = -4
|
||||
kw_pairs = 0
|
||||
if closure:
|
||||
# FIXME: fill in
|
||||
i -= 1
|
||||
|
||||
if annotate_argc:
|
||||
# Turn into subroutine and DRY with other use
|
||||
annotate_node = node[i]
|
||||
if annotate_node == "expr":
|
||||
annotate_node = annotate_node[0]
|
||||
annotate_name_node = annotate_node[-1]
|
||||
if annotate_node == "dict" and annotate_name_node.kind.startswith(
|
||||
"BUILD_CONST_KEY_MAP"
|
||||
):
|
||||
types = [
|
||||
self.traverse(n, indent="") for n in annotate_node[:-2]
|
||||
]
|
||||
names = annotate_node[-2].attr
|
||||
l = len(types)
|
||||
assert l == len(names)
|
||||
for i in range(l):
|
||||
annotate_dict[names[i]] = types[i]
|
||||
pass
|
||||
i = -4
|
||||
kw_pairs = 0
|
||||
if annotate_argc:
|
||||
# Turn into subroutine and DRY with other use
|
||||
annotate_node = node[i]
|
||||
if annotate_node == "expr":
|
||||
annotate_node = annotate_node[0]
|
||||
annotate_name_node = annotate_node[-1]
|
||||
if annotate_node == "dict" and annotate_name_node.kind.startswith(
|
||||
"BUILD_CONST_KEY_MAP"
|
||||
):
|
||||
types = [
|
||||
self.traverse(n, indent="") for n in annotate_node[:-2]
|
||||
]
|
||||
names = annotate_node[-2].attr
|
||||
l = len(types)
|
||||
assert l == len(names)
|
||||
for i in range(l):
|
||||
annotate_dict[names[i]] = types[i]
|
||||
pass
|
||||
i -= 1
|
||||
if kw_args:
|
||||
kw_node = node[i]
|
||||
if kw_node == "expr":
|
||||
kw_node = kw_node[0]
|
||||
if kw_node == "dict":
|
||||
kw_pairs = kw_node[-1].attr
|
||||
pass
|
||||
i -= 1
|
||||
|
||||
if closure:
|
||||
# FIXME: fill in
|
||||
# annotate = node[i]
|
||||
i -= 1
|
||||
|
||||
if kw_args:
|
||||
kw_node = node[pos_args]
|
||||
if kw_node == "expr":
|
||||
kw_node = kw_node[0]
|
||||
if kw_node == "dict":
|
||||
kw_pairs = kw_node[-1].attr
|
||||
|
||||
defparams = []
|
||||
# FIXME: DRY with code below
|
||||
@ -323,7 +325,9 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
self.write(" -> %s" % annotate_dict["return"])
|
||||
self.println(":")
|
||||
|
||||
if node[-2] == "docstring" and not is_lambda:
|
||||
if (
|
||||
node[-2] == "docstring" and not is_lambda
|
||||
):
|
||||
# docstring exists, dump it
|
||||
self.println(self.traverse(node[-2]))
|
||||
|
||||
@ -351,7 +355,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
|
||||
# was optimized away. Here, we need to put in unreachable code to
|
||||
# add in "yield" just so that the compiler will mark
|
||||
# the GENERATOR bit of the function. See for example
|
||||
# Python 3.x's test_generator.py test program.
|
||||
# Python 3.x's test_connection.py and test_contexlib_async test programs.
|
||||
if code.co_flags & (CO_GENERATOR | CO_ASYNC_GENERATOR):
|
||||
need_bogus_yield = True
|
||||
for token in scanner_code._tokens:
|
||||
|
Loading…
Reference in New Issue
Block a user