diff --git a/doc/whatsnew/fragments/9045.bugfix b/doc/whatsnew/fragments/9045.bugfix new file mode 100644 index 0000000000..c2a36f2e4a --- /dev/null +++ b/doc/whatsnew/fragments/9045.bugfix @@ -0,0 +1,3 @@ +Pyreverse doesn't show multiple class association arrows anymore, but only the strongest one. + +Refs #9045 diff --git a/pylint/pyreverse/writer.py b/pylint/pyreverse/writer.py index 9afdf5e2ee..093c459598 100644 --- a/pylint/pyreverse/writer.py +++ b/pylint/pyreverse/writer.py @@ -9,6 +9,7 @@ import argparse import itertools import os +from collections import defaultdict from collections.abc import Iterable from astroid import modutils, nodes @@ -133,8 +134,10 @@ def write_classes(self, diagram: ClassDiagram) -> None: rel.to_object.fig_id, type_=EdgeType.INHERITS, ) + associations: dict[str, set[str]] = defaultdict(set) # generate associations for rel in diagram.get_relationships("association"): + associations[rel.from_object.fig_id].add(rel.to_object.fig_id) self.printer.emit_edge( rel.from_object.fig_id, rel.to_object.fig_id, @@ -143,6 +146,8 @@ def write_classes(self, diagram: ClassDiagram) -> None: ) # generate aggregations for rel in diagram.get_relationships("aggregation"): + if rel.to_object.fig_id in associations[rel.from_object.fig_id]: + continue self.printer.emit_edge( rel.from_object.fig_id, rel.to_object.fig_id, diff --git a/tests/pyreverse/functional/class_diagrams/aggregation/fields.mmd b/tests/pyreverse/functional/class_diagrams/aggregation/fields.mmd index 4b23d2b4e9..9901b175c8 100644 --- a/tests/pyreverse/functional/class_diagrams/aggregation/fields.mmd +++ b/tests/pyreverse/functional/class_diagrams/aggregation/fields.mmd @@ -21,4 +21,3 @@ classDiagram P --* D : x P --* E : x P --o B : x - P --o C : x