Skip to content

Lower severity message than redundant-keyword-arg for calling distinct positional-only arg and variadic keyword arg with same name #8558

@jacobtylerwalls

Description

@jacobtylerwalls

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

PEP 570

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🪲Needs PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions