pylint icon indicating copy to clipboard operation
pylint copied to clipboard

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

Open bMorgan01 opened this issue 2 years ago • 2 comments

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

bMorgan01 avatar Nov 28 '23 03:11 bMorgan01

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.

nickdrozd avatar Nov 28 '23 16:11 nickdrozd

I have a fix for this issue. The output I get with this fix is below:

classDiagram class A { var : int } class B { a_obj func() } A --* B : a_obj

I will issue a pull request once I review the contributing guidelines and setup my environment.

pranav-data avatar Apr 09 '25 20:04 pranav-data