@@ -636,6 +636,27 @@ def add_custom_rules(self, tokens, customize):
636636 rule = ('mkfunc ::= kwargs %sexpr %s' %
637637 ('pos_arg ' * args_pos , opname ))
638638 self .add_unique_rule (rule , opname , token .attr , customize )
639+ if opname .startswith ('MAKE_FUNCTION_A' ):
640+ # rule = ('mkfunc2 ::= %s%sEXTENDED_ARG %s' %
641+ # ('pos_arg ' * (args_pos), 'kwargs ' * (annotate_args-1), opname))
642+ self .add_unique_rule (rule , opname , token .attr , customize )
643+ if self .version >= 3.3 :
644+ rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
645+ (('pos_arg ' * (args_pos )),
646+ ('call_function ' * (annotate_args - 1 )), opname ))
647+ self .add_unique_rule (rule , opname , token .attr , customize )
648+ rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
649+ (('pos_arg ' * (args_pos )),
650+ ('annotate_arg ' * (annotate_args - 1 )), opname ))
651+ else :
652+ rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
653+ (('pos_arg ' * (args_pos )),
654+ ('annotate_arg ' * (annotate_args - 1 )), opname ))
655+ self .add_unique_rule (rule , opname , token .attr , customize )
656+ rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
657+ (('pos_arg ' * (args_pos )),
658+ ('call_function ' * (annotate_args - 1 )), opname ))
659+ self .add_unique_rule (rule , opname , token .attr , customize )
639660 elif opname_base == 'CALL_METHOD' :
640661 # PyPy only - DRY with parse2
641662
@@ -696,6 +717,8 @@ def add_custom_rules(self, tokens, customize):
696717 self .check_reduce ['augassign1' ] = 'AST'
697718 self .check_reduce ['augassign2' ] = 'AST'
698719 self .check_reduce ['while1stmt' ] = 'noAST'
720+ self .check_reduce ['annotate_tuple' ] = 'noAST'
721+ self .check_reduce ['kwarg' ] = 'noAST'
699722 # FIXME: remove parser errors caused by the below
700723 # self.check_reduce['while1elsestmt'] = 'noAST'
701724 return
@@ -704,6 +727,10 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
704727 lhs = rule [0 ]
705728 if lhs in ('augassign1' , 'augassign2' ) and ast [0 ][0 ] == 'and' :
706729 return True
730+ elif lhs == 'annotate_tuple' :
731+ return not isinstance (tokens [first ].attr , tuple )
732+ elif lhs == 'kwarg' :
733+ return not isinstance (tokens [first ].attr , str )
707734 elif lhs == 'while1elsestmt' :
708735 # if SETUP_LOOP target spans the else part, then this is
709736 # not while1else. Also do for whileTrue?
0 commit comments