LOAD_CONST->LOAD_STR bugs and 3.4 kwargsonly

This commit is contained in:
rocky
2019-06-09 02:18:21 -04:00
parent 622d6f849c
commit c8fc6a704c
7 changed files with 7 additions and 13 deletions

View File

@@ -1064,19 +1064,13 @@ 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
if self.version == 3.3:
# 3.3 puts kwargs before pos_arg
pos_kw_tuple = (('kwargs ' * args_kw), ('pos_arg ' * (args_pos)))
else:
# 3.5 puts pos_arg before kwargs
# 3.4 and 3.5puts pos_arg before kwargs
pos_kw_tuple = (('pos_arg ' * (args_pos), ('kwargs ' * args_kw)))
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%s%sannotate_tuple LOAD_CONST LOAD_STR EXTENDED_ARG %s' %
rule = ('mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CONST LOAD_STR EXTENDED_ARG %s' %
( pos_kw_tuple[0], pos_kw_tuple[1],
('call ' * (annotate_args-1)), opname))
self.add_unique_rule(rule, opname, token.attr, customize)

View File

@@ -88,7 +88,7 @@ def customize_for_version3(self, version):
code_node = build_class[1][0]
class_name = code_node.attr.co_name
else:
class_name = node[1][0].pattr
class_name = node[1][0].attr
build_class = node[0]
assert 'mkfunc' == build_class[1]

View File

@@ -216,7 +216,7 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
if (line_number != self.line_number):
self.write("\n" + indent)
line_number = self.line_number
kn = n[0].pattr
kn = n[0].attr
if kn in annotate_tuple[0].attr:
p = annotate_tuple[0].attr.index(star_arg) + pos_args + kw_args
self.write('%s: ' % kn)

View File

@@ -1436,7 +1436,7 @@ class SourceWalker(GenericASTTraversal, object):
n = len(node) - 1
if node.kind != 'expr':
if node == 'kwarg':
self.template_engine(('(%[0]{pattr}=%c)', 1), node)
self.template_engine(('(%[0]{attr}=%c)', 1), node)
return
kwargs = None