Description
Current problem
When writing a function, you can defeat the point of a PEP 570 positional-only argument (to the left of /
) if:
- it has a default
- later, there is a variadic positional-or-keyword argument e.g.
**kwargs
GOOD example (adapted from PEP 570, "Semantic Corner Case"):
def foo(name, /, **kwds):
return name
See that name is actually positional-only:
>>> foo(name="Jacob")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() missing 1 required positional argument: 'name'
BAD example:
def foo(name="Sarah", /, **kwds):
return name
See that name is completely ignored:
>>> foo(name="Jacob")
'Sarah'
Desired solution
I suggest a new warning e.g. defeated-positional-only-argument
Additional context
Inspired by #8555