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.27k stars 1.12k forks source link

Pyreverse: Duplicate arrows when class attribute is assigned more than once #9267

Open bMorgan01 opened 10 months ago

bMorgan01 commented 10 months ago

Bug description

I get an issue similar to https://github.com/pylint-dev/pylint/issues/8522, but it seems to have a different cause. Supposedly this issue was fixed in pylint 3.0.0, but I still see it.

Code:

class A:
    def __init__(self) -> None:
        self.var = 2

class B:
    def __init__(self) -> None:
        self.a_obj = A()

    def func(self):
        self.a_obj = A()
        self.a_obj = A()

Result: classes

Configuration

No response

Command used

pyreverse . -o png

Pylint output

Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
Analysed 2 modules with a total of 0 imports

Expected behavior

Duplicate arrows do not appear

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]

OS / Environment

Windows 10 / powershell

Additional dependencies

No response

nickdrozd commented 10 months ago

The previous issue had to do with the duplication between field declarations and assignments, while this one has to do with multiple assignments. There are many ways to create duplicates in Pyreverse!

For anyone who wants to fix this one, take a look at https://github.com/pylint-dev/pylint/pull/9029.