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.32k stars 1.14k forks source link

Pyreverse: Aggregation/compostion doesn't work across modules. #9271

Open bMorgan01 opened 11 months ago

bMorgan01 commented 11 months ago

Bug description

I have a project with this structure:

pyreverse_test
     __init__.py
     a.py
     b.py

a.py contains:

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

b.py contains:

from a import A

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

Running pyreverse yields this result: classes0

Configuration

No response

Command used

Working directory: pyreverse_test

pyreverse . -f ALL -o png

Pylint output

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

Expected behavior

I expect the result to match this, un-separated, code.

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

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

Which is this: classes

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 11 months ago

This works in some cases but not others. I have no idea why.