From: Stefan Behnel Date: Tue, 2 Nov 2010 13:27:17 +0000 (+0100) Subject: fix *args/**kwargs in lambda function declaration: was messed up with annotation... X-Git-Tag: 0.14.alpha0~263 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8c5adff1245e21e2ceee56d110a6e8367db618dd;p=cython.git fix *args/**kwargs in lambda function declaration: was messed up with annotation syntax --- diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 8df5ca10..72471e8d 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2568,23 +2568,23 @@ def p_varargslist(s, terminator=')', annotated=1): 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) diff --git a/tests/run/lambda_T195.pyx b/tests/run/lambda_T195.pyx index 3a298eb2..447f3d4f 100644 --- a/tests/run/lambda_T195.pyx +++ b/tests/run/lambda_T195.pyx @@ -76,3 +76,35 @@ def make_typed_lambda_lambda(int x): """ 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'])