def p_typedargslist_kwarg(self, p): """typedargslist : POW tfpdef""" p[0] = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[2], defaults=[], )
def p_typedargslist_times4_comma(self, p): """typedargslist : TIMES comma_pow_tfpdef""" # *, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[2], defaults=[], ) p[0] = p0
def p_varargslist_times4(self, p): """varargslist : TIMES vfpdef_opt comma_pow_vfpdef_opt""" p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[], ) self._set_var_args(p0, p[2], None) p[0] = p0
def p_parameters(self, p): """parameters : LPAREN typedargslist_opt RPAREN""" p2 = p[2] if p2 is None: p2 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ) p[0] = p2
def p_varargslist_v11(self, p): """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt TIMES vfpdef_opt comma_vfpdef_list COMMA POW vfpdef""" p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[10], defaults=[], ) self._set_regular_args(p0, p[1], p[2], p[3], p[4]) self._set_var_args(p0, p[6], p[7]) p[0] = p0
def p_varargslist_v5(self, p): """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt""" # x p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ) self._set_regular_args(p0, p[1], p[2], p[3], p[4]) p[0] = p0
def p_varargslist_times5(self, p): """varargslist : TIMES vfpdef_opt comma_vfpdef_list comma_pow_vfpdef_opt""" # *args, x, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[4], defaults=[], ) self._set_var_args(p0, p[2], p[3]) # *args p[0] = p0
def p_typedargslist_t8(self, p): """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt TIMES tfpdef_opt comma_tfpdef_list_opt""" p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ) self._set_regular_args(p0, p[1], p[2], p[3], p[4]) self._set_var_args(p0, p[6], p[7]) p[0] = p0
def p_typedargslist_t7(self, p): """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt POW tfpdef""" # x, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[6], defaults=[], ) self._set_regular_args(p0, p[1], p[2], p[3], p[4]) p[0] = p0
def p_typedargslist_times5_comma(self, p): """typedargslist : TIMES comma_tfpdef_list comma_pow_tfpdef_opt""" # *, x, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[], ) self._set_var_args(p0, None, p[2]) # *args p[0] = p0
def p_typedargslist_times4_tfpdef(self, p): """typedargslist : TIMES tfpdef comma_pow_tfpdef_opt""" # *args, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[], ) self._set_var_args(p0, p[2], None) p[0] = p0
def test_add_inline_comment_func(): code = """ # comment 1 def func(): # comment 2 # comment 3 True # comment 4 # comment 5 # comment 6 """ exp = Module( body=[ Comment(s="# comment 1", lineno=1, col_offset=0), NodeWithComment( node=FunctionDef( name="func", args=arguments( args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ), body=[ Comment(s="# comment 3", lineno=3, col_offset=4), NodeWithComment( node=Expr( value=NameConstant(value=True, lineno=4, col_offset=4), lineno=4, col_offset=4, ), comment=Comment(s="# comment 4", lineno=4, col_offset=10), lineno=4, col_offset=4, ), Comment(s="# comment 5", lineno=5, col_offset=4), ], decorator_list=[], returns=None, lineno=2, col_offset=0, ), comment=Comment(s="# comment 2", lineno=2, col_offset=13), lineno=2, col_offset=0, ), Comment(s="# comment 6", lineno=6, col_offset=0), ] ) check_add_comments(code, exp)
def p_varargslist_v10(self, p): """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt TIMES vfpdef_opt COMMA POW vfpdef""" # x, *args, **kwargs p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[9], defaults=[], ) self._set_regular_args(p0, *p[1:5]) self._set_var_args(p0, p[6], None) p[0] = p0
def p_posonlyvarargslist(self, p): """posonlyvarargslist : vfpdef equals_test_opt COMMA DIVIDE | vfpdef equals_test_opt comma_vfpdef_list COMMA DIVIDE""" p0 = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ) if p[3] == ",": self._set_posonly_args(p0, p[1], p[2], None) else: self._set_posonly_args(p0, p[1], p[2], p[3]) p[0] = p0
def p_lambdef(self, p): """lambdef : lambda_tok varargslist_opt COLON test""" p1, p2, p4 = p[1], p[2], p[4] if p2 is None: args = ast.arguments( posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[], ) else: args = p2 p0 = ast.Lambda(args=args, body=p4, lineno=p1.lineno, col_offset=p1.lexpos) p[0] = p0