From 3496fe2a678faed9f3d788dceb932dff6d25cb66 Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Thu, 21 Sep 2023 10:12:36 -0400 Subject: [PATCH 1/2] Don't show multiple class association arrows --- doc/whatsnew/fragments/9045.bugfix | 3 +++ pylint/pyreverse/writer.py | 5 +++++ .../functional/class_diagrams/aggregation/fields.mmd | 1 - 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 doc/whatsnew/fragments/9045.bugfix diff --git a/doc/whatsnew/fragments/9045.bugfix b/doc/whatsnew/fragments/9045.bugfix new file mode 100644 index 0000000000..d26da41568 --- /dev/null +++ b/doc/whatsnew/fragments/9045.bugfix @@ -0,0 +1,3 @@ +Don't show multiple class association arrows. + +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 From 4869dd8b854bb67ec413949af89f5d58b4848a60 Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Fri, 22 Sep 2023 10:11:22 -0400 Subject: [PATCH 2/2] Update bugfix description --- doc/whatsnew/fragments/9045.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whatsnew/fragments/9045.bugfix b/doc/whatsnew/fragments/9045.bugfix index d26da41568..c2a36f2e4a 100644 --- a/doc/whatsnew/fragments/9045.bugfix +++ b/doc/whatsnew/fragments/9045.bugfix @@ -1,3 +1,3 @@ -Don't show multiple class association arrows. +Pyreverse doesn't show multiple class association arrows anymore, but only the strongest one. Refs #9045