Skip to content

Parameter range is incorrect for *args and **kwargs #10282

@GtrMo

Description

@GtrMo

I'm working on a fix for the flake8-unused-arguments (ARG) rules that would delete them.

While working on this, I noticed that the *args and **kwargs Parameter.range does not include the *.
I think that Parameter.range should include * or **, leaving Parameter.name.range for the actual name range if needed.

def f(*args, **kwargs): pass
#      ~~~~    ~~~~~~    <-- actual range
#     ^^^^^  ^^^^^^^^    <-- expected range
See the currently generated AST

vararg: Some(
Parameter {
range: 16..20,
name: Identifier {
id: "args",
range: 16..20,
},
annotation: None,
},
),

Here I would expect the Parameter range to be 1 longer than the Identifier range.

kwarg: Some(
Parameter {
range: 39..45,
name: Identifier {
id: "kwargs",
range: 39..45,
},
annotation: None,
},
),
},

And here I would expect the Parameter range to be 2 longer than the Identifier range.

If this is indeed considered a bug, I have a PR ready to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    internalAn internal refactor or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions