pylint icon indicating copy to clipboard operation
pylint copied to clipboard

pyreverse Aggregation and Composition arrows are same

Open khashashin opened this issue 3 years ago • 0 comments

Bug description

pyreverse generates same diagram for aggregation and composition. Here is the sample code:

# Aggregation
class Student:
    def __init__(self, id):
        self._id = id

    def registration_number(self, department_id):
        return str(self._id) + '-' + department_id


class Department:
    def __init__(self, id, student):
        self._id = id
        self._student = student

    def student_registration(self):
        return self._student.registration_number(self._id)


if __name__ == '__main__':
    student = Student(50)
    department = Department('ENG', student)

    print(department.student_registration())

# Composition
class Student:
    def __init__(self, id):
        self._id = id

    def registration_number(self, department_id):
        return str(self._id) + '-' + department_id


class Department:
    def __init__(self, department_id, student_id):
        self._id = department_id
        self._student = Student(student_id)

    def student_registration(self):
        return self._student.registration_number(self._id)


if __name__ == '__main__':
    department = Department('ENG', 50)

    print(department.student_registration())

Configuration

No response

Command used

pyreverse -o png -p composition.py .
pyreverse -o png -p aggregation.py .

Pylint output

Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
parsing ./__init__.py...
parsing /mnt/d/GitHub/test/django_with_sass/experiments/composition.py...
parsing /mnt/d/GitHub/test/django_with_sass/experiments/__init__.py...

Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
parsing ./__init__.py...
parsing /mnt/d/GitHub/test/django_with_sass/experiments/aggregation.py...
parsing /mnt/d/GitHub/test/django_with_sass/experiments/__init__.py...

Expected behavior

Different Arrow type.

image Source

Pylint version

pylint --version
pylint 2.13.8
astroid 2.11.4
Python 3.10.0 (default, Dec  3 2021, 00:34:18) [GCC 9.3.0]

OS / Environment

Windows 11 WSL2

Additional dependencies

sudo apt install graphviz

khashashin avatar May 07 '22 21:05 khashashin