pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.24k stars 1.12k forks source link

consider-augmented-assign false positive #8086

Closed SimonSchick closed 1 year ago

SimonSchick commented 1 year ago

Bug description

Currently this checker doesn't appear to pay attention to the context of a field lookup and assumes that as long as the field name matches it can proceed, example:

class A:
    def __init__(self) -> None:
        self.a = 1
        self.b = A()

    def test(self) -> None:
        self.a = self.a + 1 # should flag
        self.b.a = self.a + 1 # should NOT flag, the error is here

Configuration

Appears to be not relevant as long as the offending rule is enabled

Command used

Please don't scream, we need to move things around (suggestions welcome either way).

`find . -type f -name "*.py" -not -path "./.env/*" -not -path "*/src/common/*" | xargs pylint --jobs 4 --init-hook "import sys; sys.path.append(\"$PWD\")"`

Pylint output

`Use '+=' to do an augmented assign directlypylint(consider-using-augmented-assign)`

Expected behavior

The false positive should not be reported

Pylint version

pylint 2.16.0b0
astroid 2.13.2
Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)]

OS / Environment

MacOS

Additional dependencies

No response

cdce8p commented 1 year ago

This is probably an issue for 2.15.x as well. Removed the Unreleased label. Opened #8088 with a fix.

Pierre-Sassoulas commented 1 year ago

Are you sure we introduced this check in https://github.com/PyCQA/pylint/issues/7605 ?

Pierre-Sassoulas commented 1 year ago

Well it was modified a lot : https://github.com/PyCQA/pylint/pull/7628 based on https://github.com/PyCQA/pylint/pull/7514. I also consider making a special case for anti-commutative operator, I might as well :D

cdce8p commented 1 year ago

Are you sure we introduced this check in #7605 ?

I only checked git blame and saw that it was added last November, so I though it must have been released yet. Seems I was wrong 😄

Pierre-Sassoulas commented 1 year ago

Ho, because we release a lot of patch version it does not seem like it, but time fly and 2.15.0 was released in late AUGUST (!!)