3.3-3.4 pos kwargs ordering

This commit is contained in:
rocky 2019-06-08 18:40:50 -04:00
parent 9fe1752359
commit 86fd5dbf7a
6 changed files with 13 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -25,9 +25,8 @@ def test7(*varargs: int, **kwargs):
def test8(x=55, *varargs: int, **kwargs) -> list:
return (x, varargs, kwargs)
#def test9(x=55, *varargs: int, y=5, **kwargs):
# return x, varargs, int, y, kwargs
def test9(arg_1=55, *varargs: int, y=5, **kwargs):
return x, varargs, int, y, kwargs
def test10(args_1, b: 'annotating b', c: int) -> float:
return 5.4
@ -75,6 +74,8 @@ def ann2(args_1, b: int = 5, **kwargs: float) -> float:
assert test1(1, 5) == (1, 5, 4, {})
assert test1(1, 5, 6, foo='bar') == (1, 5, 6, {'foo': 'bar'})
assert test2(2, 3, 4) == (2, 3, 4, 4, (), {})
assert test3(10, foo='bar') == 5.4
assert test4(9.5, 7, 6, 4, bar='baz') == 5.4
### FIXME: fill in...
assert test6(1.2, 3) == (1.2, 3, None)
assert test6(2.3, 4, 5) == (2.3, 4, 5)

View File

@ -1064,12 +1064,18 @@ class Python3Parser(PythonParser):
# Normally we remove EXTENDED_ARG from the opcodes, but in the case of
# annotated functions can use the EXTENDED_ARG tuple to signal we have an annotated function.
# Yes this is a little hacky
if self.version < 3.5:
# 3.3 and 3.4 put kwargs before pos_arg
pos_kw_tuple = (('kwargs ' * args_kw), ('pos_arg ' * (args_pos)))
else:
# 3.5 puts pos_arg before kwargs
pos_kw_tuple = (('pos_arg ' * (args_pos), ('kwargs ' * args_kw)))
rule = ('mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos), ('kwargs ' * args_kw),
('call ' * (annotate_args-1)), opname)))
( pos_kw_tuple[0], pos_kw_tuple[1],
('call ' * (annotate_args-1)), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)), ('kwargs ' * args_kw),
( pos_kw_tuple[0], pos_kw_tuple[1],
('annotate_arg ' * (annotate_args-1)), opname))
else:
# See above comment about use of EXTENDED_ARG