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

Do not suggest augmented assigns for non-commutative operations with the target as the right operand #7639

Closed
bchardin opened this issue Oct 17, 2022 · 3 comments · Fixed by #8037
Assignees
Labels
Blocker 🙅 Blocks the next release False Positive 🦟 A message is emitted but nothing is wrong with the code Unreleased
Milestone

Comments

@bchardin
Copy link
Contributor

Bug description

Pylint suggests augmented assigns for non-commutative binary operations, even when the assignment target is the right operand.

"""Minimal example where a C0210 message is displayed even though a simple
transformation does not seem possible.
"""

# pylint: disable=invalid-name

x = 1
x = 1 - x
x = 2 / x

Configuration

No response

Command used

pylint c0210_issue.py

Pylint output

************* Module c0210_issue
c0210_issue.py:8:0: C0210: Use '-=' to do an augmented assign directly (consider-using-augmented-assign)
c0210_issue.py:9:0: C0210: Use '/=' to do an augmented assign directly (consider-using-augmented-assign)

------------------------------------------------------------------
Your code has been rated at 3.33/10 (previous run: 3.33/10, +0.00)

Expected behavior

No error should be displayed.

Pylint version

pylint 2.16.0-dev
astroid 2.12.10
Python 3.8.5 (default, Sep  7 2020, 16:44:59) [GCC 6.3.0 20170516]

OS / Environment

Debian 9.13 (stretch)

Additional dependencies

No response

@bchardin bchardin added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 17, 2022
@bchardin
Copy link
Contributor Author

This is linked to a feature (to be) introduced with the 2.16 version by #7514.

@Pierre-Sassoulas
Copy link
Member

Awesome bug report, thank you for beta-testing pylint 👌 @clavedeluna @DanielNoord do you want to handle this considering you implemented #7514 together ?

@Pierre-Sassoulas Pierre-Sassoulas added Blocker 🙅 Blocks the next release False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 17, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Oct 17, 2022
@DanielNoord
Copy link
Collaborator

I think we should just disable the checker for anything where the assignee is not in the left hand side of the equation. I thought I found all cases where it can be on the right, but clearly I didn't have my maths correctly 😓

I don't know if I have much time to prepare a PR but I can definitely help with review!

@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jan 9, 2023
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jan 9, 2023
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jan 9, 2023
…rators

Or rather, only warn for known commutative operators.

Closes pylint-dev#7639
Pierre-Sassoulas added a commit that referenced this issue Jan 9, 2023
…rators (#8037)

Or rather, only warn for known commutative operators.

Closes #7639

Co-authored-by: Nick Drozd <nicholasdrozd@gmail.com>
Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker 🙅 Blocks the next release False Positive 🦟 A message is emitted but nothing is wrong with the code Unreleased
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants