pythonwhat
pythonwhat copied to clipboard
test_function_definition does not test kwonly args
kwonly args are those that follow an *args in a signature. This is because it's impossible to assign them by position. For example, d
below...
def func(a, b, c=1, *args, d=2, **kwargs): pass
However, it appears that test_function_definition currently only tests positional and keyword args that occur before *args
. AST dump below...
Module(body=[
FunctionDef(name='func', args=arguments(args=[
arg(arg='a', annotation=None),
arg(arg='b', annotation=None),
arg(arg='c', annotation=None),
], vararg=arg(arg='args', annotation=None), kwonlyargs=[
arg(arg='d', annotation=None),
], kw_defaults=[
Num(n=2),
], kwarg=arg(arg='kwargs', annotation=None), defaults=[
Num(n=1),
]), body=[
Pass(),
], decorator_list=[], returns=None),
])
test_function_definition
parses each entry, but only uses the args
(that is, pos and kw) in its tests. Fixing may not have much impact, since kwonly args are pretty rare, but leaving here to address once it is rewritten using the new spec.
A lot of people don't know about KW only args, so let's icebox this until a use case arises.