Skip to content

Fix unused variable removal for keyword arguments - #374

Open
Sanjays2402 wants to merge 1 commit into
PyCQA:mainfrom
Sanjays2402:fix/unused-variable-keyword-arguments
Open

Sanjays2402 wants to merge 1 commit into
PyCQA:mainfrom
Sanjays2402:fix/unused-variable-keyword-arguments

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Fixes #372.

An assignment such as user = User.objects.get(id=id) was left unchanged because the removal logic counted every = character as an assignment. Parse the statement to recognize a single name target, then preserve the original expression when removing the unused binding. Chained assignments, unpacking, attribute/subscript assignments, and multiline statements remain unchanged.

With --remove-rhs-for-unused-variables, insert a temporary pass so removing the only statement leaves valid Python; the existing cleanup removes that placeholder when another statement remains.

Validation: all 182 tests in test_autoflake.py passed, including 11 subtests; new regressions failed against unchanged main. The pinned Ty type check, Ruff checks/formatting and the project's fuzz script on both changed Python files passed. Prepared with Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--remove-unused-variables does not work

1 participant