ruff
77c2f4c6 - [`flake8-unused-arguments`] Mark `**kwargs` in `TypeVar` as used (`ARG001`) (#22214)

Commit
52 days ago
[`flake8-unused-arguments`] Mark `**kwargs` in `TypeVar` as used (`ARG001`) (#22214) ## Summary Fixes false positive in ARG001 when `**kwargs` is passed to `typing.TypeVar` Closes #22178 When `**kwargs` is used in a `typing.TypeVar` call, the checker was not recognizing it as a usage, leading to false positive "unused function argument" warnings. ### Root Cause In the AST, keyword arguments are represented by the `Keyword` struct with an `arg` field of type `Option<Identifier>`: - Named keywords like `bound=int` have `arg = Some("bound")` - Dictionary unpacking like `**kwargs` has `arg = None` The existing code only handled the `Some(id)` case, never visiting the expression when `arg` was `None`, so `**kwargs` was never marked as used. ### Changes Added an `else` branch to handle `**kwargs` unpacking by calling `visit_non_type_definition(value)` when `arg` is `None`. This ensures the `kwargs` variable is properly visited and marked as used by the semantic model. ## Test Plan Tested with the following code: ```python import typing def f( *args: object, default: object = None, **kwargs: object, ) -> None: typing.TypeVar(*args, **kwargs) ``` Before : `ARG001 Unused function argument: kwargs ` After : `All checks passed!` Run the example with the following command(from the root of ruff and please change the path to the module that contains the code example): `cargo run -p ruff -- check /path/to/file.py --isolated --select=ARG --no-cache`
Author
Parents
Loading