Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unused assignments in use-walrus-if codemod #264

Closed
drdavella opened this issue Feb 14, 2024 · 1 comment · Fixed by #477
Closed

Handle unused assignments in use-walrus-if codemod #264

drdavella opened this issue Feb 14, 2024 · 1 comment · Fixed by #477
Assignees
Labels
enhancement New feature or request

Comments

@drdavella
Copy link
Member

Details

In some cases the use-walrus-if codemod makes a change such that the involved variable is no longer used at all. In other words, the original conditional is the only place where the result of the assignment was used.

We can use the scope provider and parent metadata in libCST to determine which such cases occur. In these cases we should not rewrite with the walrus operator at all but simply use the RHS of the original assign expression as the conditional value without any assignment at all.

We can actually see an example where the current behavior causes our own pipelines to fail in #258.

@drdavella
Copy link
Member Author

This is reasonably urgent because it causes pylint jobs to fail when the assignment is no longer used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants