From 3bb75c45c95ccf56106097240728061803244289 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 28 Oct 2008 21:33:44 -0700 Subject: [PATCH] more arg parsing fixes --- Cython/Compiler/Nodes.py | 7 +++---- tests/run/callargs.pyx | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 9e6b2b2a..bfe9b410 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1976,16 +1976,15 @@ class DefNode(FuncDefNode): code.put('case %2d: ' % (i+1)) item = "PyTuple_GET_ITEM(%s, %d)" % (Naming.args_cname, i) self.generate_arg_assignment(arg, item, code) + if min_positional_args == 0: + code.put('case 0: ') + code.putln('break;') if self.star_arg: if min_positional_args: - code.putln('break;') for i in range(min_positional_args-1, -1, -1): code.putln('case %2d:' % i) code.put_goto(argtuple_error_label) else: - if min_positional_args == 0: - code.put('case 0: ') - code.putln('break;') code.put('default: ') code.put_goto(argtuple_error_label) code.putln('}') diff --git a/tests/run/callargs.pyx b/tests/run/callargs.pyx index 05ea79d6..fa44e649 100644 --- a/tests/run/callargs.pyx +++ b/tests/run/callargs.pyx @@ -110,9 +110,25 @@ __doc__ = u""" 1 2 0 1 >>> d(1,2,3, key=None) 1 2 1 1 - + + >>> c() + 10 20 0 + >>> c(1) + 1 20 0 + >>> c(1,2) + 1 2 0 + >>> c(key=None) + 10 20 1 + >>> c(1, key=None) + 1 20 1 + >>> c(1,2, key=None) + 1 2 1 + """ +def c(a=10, b=20, **kwds): + print a, b, len(kwds) + def d(a, b=1, *args, **kwds): print a, b, len(args), len(kwds) -- 2.26.2