Skip to content

Commit

Permalink
Pyreverse: Don't show multiple class association arrows (#9055)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
nickdrozd and Pierre-Sassoulas authored Sep 25, 2023
1 parent 65959d3 commit 209f234
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9045.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pyreverse doesn't show multiple class association arrows anymore, but only the strongest one.

Refs #9045
5 changes: 5 additions & 0 deletions pylint/pyreverse/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import argparse
import itertools
import os
from collections import defaultdict
from collections.abc import Iterable

from astroid import modutils, nodes
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ classDiagram
P --* D : x
P --* E : x
P --o B : x
P --o C : x

0 comments on commit 209f234

Please sign in to comment.