diff --git a/doc/whatsnew/fragments/10373.bugfix b/doc/whatsnew/fragments/10373.bugfix new file mode 100644 index 0000000000..d7ba3a1893 --- /dev/null +++ b/doc/whatsnew/fragments/10373.bugfix @@ -0,0 +1,3 @@ +Fix a bug in Pyreverse where aggregations and associations were included in diagrams regardless of the selected --filter-mode (such as PUB_ONLY, ALL, etc.). + +Closes #10373 diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 6db0563003..a4fb8ce130 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -237,6 +237,9 @@ def extract_relationships(self) -> None: # associations & aggregations links for name, values in list(node.aggregations_type.items()): for value in values: + if not self.show_attr(name): + continue + self.assign_association_relationship( value, obj, name, "aggregation" ) @@ -249,6 +252,9 @@ def extract_relationships(self) -> None: for name, values in associations.items(): for value in values: + if not self.show_attr(name): + continue + self.assign_association_relationship( value, obj, name, "association" ) diff --git a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd new file mode 100644 index 0000000000..7dc9f77d98 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd @@ -0,0 +1,9 @@ +classDiagram + class A { + x + } + class B { + } + class P { + } + P --* A : x diff --git a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py new file mode 100644 index 0000000000..8c87070f33 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py @@ -0,0 +1,10 @@ +# Test for https://github.com/pylint-dev/pylint/issues/10373 + +class P: + pass + +class A: + x: P = P() + +class B: + __x: P = P()