Daniel Urban added the comment:

If I understand correctly, the invariant is that len(kw_defaults) == 
len(kwonlyargs). I think the reason is that the following is valid syntax (an 
argument without a default after one with a default):

>>> def f(*, a=0, b): pass

And None is used as a placeholder in the kw_defaults list:
>>> ast.dump(ast.parse('def f(*, a=0, b): pass'))
"Module(body=[FunctionDef(name='f', args=arguments(args=[], vararg=None, 
varargannotation=None, kwonlyargs=[arg(arg='a', annotation=None), arg(arg='b', 
annotation=None)], kwarg=None, kwargannotation=None, defaults=[], 
kw_defaults=[Num(n=0), None]), body=[Pass()], decorator_list=[], 

So it seems to me, that this behavior is intentional. (Also, it works no 
differently in 3.2.)


Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to