if s.sy == '*':
s.next()
if s.sy == 'IDENT':
- star_arg = p_py_arg_decl(s)
+ star_arg = p_py_arg_decl(s, annotated=annotated)
if s.sy == ',':
s.next()
args.extend(p_c_arg_list(s, in_pyfunc = 1,
- nonempty_declarators = 1, kw_only = 1))
+ nonempty_declarators = 1, kw_only = 1, annotated = annotated))
elif s.sy != terminator:
s.error("Syntax error in Python function argument list")
if s.sy == '**':
s.next()
- starstar_arg = p_py_arg_decl(s)
+ starstar_arg = p_py_arg_decl(s, annotated=annotated)
return (args, star_arg, starstar_arg)
-def p_py_arg_decl(s):
+def p_py_arg_decl(s, annotated = 1):
pos = s.position()
name = p_ident(s)
annotation = None
- if s.sy == ':':
+ if annotated and s.sy == ':':
s.next()
annotation = p_test(s)
return Nodes.PyArgDeclNode(pos, name = name, annotation = annotation)
"""
return lambda int y : \
lambda int z:x+y+z
+
+def pass_lambda(f):
+ """
+ >>> def f(a, lfunc): return lfunc(a,2)
+ >>> pass_lambda(f)
+ 12
+ """
+ return f(1, lambda a, b : a*10+b)
+
+def pass_lambda_with_args(f):
+ """
+ >>> def f(a, lfunc): return lfunc(a,2,3)
+ >>> pass_lambda_with_args(f)
+ 123
+ """
+ return f(1, lambda a, *args : (a*10 + args[0])*10 + args[1])
+
+def pass_lambda_with_args_kwargs(f):
+ """
+ >>> def f(a, lfunc): return lfunc(a,2,3, b=4)
+ >>> pass_lambda_with_args_kwargs(f)
+ 1234
+ """
+ return f(1, lambda a, *args, **kwargs : ((a*10 + args[0])*10 + args[1])*10 + kwargs['b'])
+
+def pass_lambda_with_args_kwargs_kwonly_args(f):
+ """
+ >>> def f(a, lfunc): return lfunc(a,2,3, b=4, c=5)
+ >>> pass_lambda_with_args_kwargs_kwonly_args(f)
+ 12345
+ """
+ return f(1, lambda a, *args, b, **kwargs : (((a*10 + args[0])*10 + args[1])*10 + b)*10 + kwargs['c'])