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

non-augmented-assignment (PLR6104) - false positive on operators where the variable is on the other side #10900

Closed
DetachHead opened this issue Apr 12, 2024 · 5 comments · Fixed by #10909
Assignees
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features

Comments

@DetachHead
Copy link

a = 1
a = 0 / a  # PLR6104: Use `/=` to perform an augmented assignment directly

playground

in this example, the quickfix converts it to a /= 0 which causes a runtime ZeroDivisionError

@MichaReiser MichaReiser added bug Something isn't working preview Related to preview mode features labels Apr 12, 2024
@MichaReiser
Copy link
Member

MichaReiser commented Apr 12, 2024

CC: @lshi18

@MichaReiser MichaReiser added the help wanted Contributions especially welcome label Apr 12, 2024
@DetachHead DetachHead changed the title non-augmented-assignment (PLR6104) - false positive on operatrors where the variable is on the other side non-augmented-assignment (PLR6104) - false positive on operators where the variable is on the other side Apr 12, 2024
@lshi18
Copy link
Contributor

lshi18 commented Apr 12, 2024

Hi @MichaReiser, I think that this implementation is only correct for commutative binary operators, but fails for others such as "/".

And thank @charliermarsh for completing the work in #9932 .

@charliermarsh
Copy link
Member

Ah thanks, I’ll fix that today!

@NeilGirdhar
Copy link

NeilGirdhar commented Apr 12, 2024

@charliermarsh Is this fixed for:

test_string = "desired = " + test_string  # False positive PLR6104

since + is sometimes commutative.

@charliermarsh
Copy link
Member

No, I'll fix that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants