if self.star_arg:
code.putln('default:')
for i in range(max_positional_args-1, -1, -1):
- code.putln('case %d:' % (i+1))
+ code.put('case %2d: ' % (i+1))
code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (
i, Naming.args_cname, i))
- code.putln('case 0: break;')
+ code.putln('case 0: break;')
if not self.star_arg:
code.put('default: ') # more arguments than allowed
code.put_goto(argtuple_error_label)
if self.star_arg and i == max_positional_args:
code.putln('default:')
else:
- code.putln('case %d:' % i)
+ code.putln('case %2d:' % i)
code.putln('values[%d] = PyDict_GetItem(%s, *%s[%d]);' % (
i, Naming.kwds_cname, Naming.pykwdlist_cname, i))
if i < min_positional_args:
if self.num_required_kw_args:
# pure error case: keywords required but not passed
+ if max_positional_args > min_positional_args and not self.star_arg:
+ code.putln('} else if (PyTuple_GET_SIZE(%s) > %d) {' % (
+ Naming.args_cname, max_positional_args))
+ code.put_goto(argtuple_error_label)
code.putln('} else {')
- if not self.star_arg and not self.starstar_arg:
- # optional args missing?
- self.generate_positional_args_check(
- max_positional_args, has_fixed_positional_count, code)
for i, arg in enumerate(kw_only_args):
if not arg.default:
# required keyword-only argument missing
reversed_args = list(enumerate(positional_args))[::-1]
for i, arg in reversed_args:
if i >= min_positional_args-1:
- code.putln('case %d:' % (i+1))
+ if min_positional_args > 1:
+ code.putln('case %2d:' % (i+1)) # pure code beautification
+ else:
+ code.put('case %2d: ' % (i+1))
item = "PyTuple_GET_ITEM(%s, %d)" % (Naming.args_cname, i)
self.generate_arg_assignment(arg, item, code)
if not self.star_arg:
if min_positional_args == 0:
- code.putln('case 0:')
+ code.put('case 0: ')
code.putln('break;')
code.put('default: ')
code.put_goto(argtuple_error_label)
>>> call2d(k)
Traceback (most recent call last):
TypeError: k() needs keyword-only argument f
+
+ >>> call0abc(m)
+ 1 2 3
+ >>> call2c(m)
+ 1 2 1
+
+ >>> call3(m)
+ Traceback (most recent call last):
+ TypeError: m() takes at most 2 positional arguments (3 given)
+ >>> call2(m)
+ Traceback (most recent call last):
+ TypeError: m() needs keyword-only argument c
+ >>> call2cd(m)
+ Traceback (most recent call last):
+ TypeError: 'd' is an invalid keyword argument for this function
"""
# the calls:
kwlist = list(kwds.items())
kwlist.sort()
print a,b,c,d,e,f, args, kwlist
+
+def m(a, b=1, *, c):
+ print a,b,c