From 7e2b8009697caf92df13760164c1c2b724821a7c Mon Sep 17 00:00:00 2001 From: pavan-msys Date: Wed, 14 May 2025 16:44:02 +0530 Subject: [PATCH 1/5] updated diagrams.py file --- doc/whatsnew/fragments/10373.bugfix | 3 +++ pylint/pyreverse/diagrams.py | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 doc/whatsnew/fragments/10373.bugfix diff --git a/doc/whatsnew/fragments/10373.bugfix b/doc/whatsnew/fragments/10373.bugfix new file mode 100644 index 0000000000..2aca16073c --- /dev/null +++ b/doc/whatsnew/fragments/10373.bugfix @@ -0,0 +1,3 @@ +Fixed 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..fd3f616739 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" ) From a9f29a19a84156eb12054f15c13ac61fbd54a86d Mon Sep 17 00:00:00 2001 From: pavan-msys Date: Wed, 14 May 2025 17:51:26 +0530 Subject: [PATCH 2/5] added tests --- doc/whatsnew/fragments/10373.bugfix | 4 ++-- tests/functional/t/test_aggregation_filtering.py | 11 +++++++++++ tests/functional/t/test_aggregation_filtering.txt | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/functional/t/test_aggregation_filtering.py create mode 100644 tests/functional/t/test_aggregation_filtering.txt diff --git a/doc/whatsnew/fragments/10373.bugfix b/doc/whatsnew/fragments/10373.bugfix index 2aca16073c..59310028c2 100644 --- a/doc/whatsnew/fragments/10373.bugfix +++ b/doc/whatsnew/fragments/10373.bugfix @@ -1,3 +1,3 @@ -Fixed a bug in Pyreverse where aggregations and associations were included in diagrams regardless of the selected --filter-mode (such as PUB_ONLY, ALL, etc.). +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 +Closes #10373 \ No newline at end of file diff --git a/tests/functional/t/test_aggregation_filtering.py b/tests/functional/t/test_aggregation_filtering.py new file mode 100644 index 0000000000..b2c898906b --- /dev/null +++ b/tests/functional/t/test_aggregation_filtering.py @@ -0,0 +1,11 @@ +class P: + pass + +class A: + x: P = P() + +class B: + __x: P = P() + +class C: + _y: P = P() diff --git a/tests/functional/t/test_aggregation_filtering.txt b/tests/functional/t/test_aggregation_filtering.txt new file mode 100644 index 0000000000..f51d6cbaec --- /dev/null +++ b/tests/functional/t/test_aggregation_filtering.txt @@ -0,0 +1,11 @@ +classDiagram + class A { + x + } + class B { + } + class C { + } + class P { + } + P --* A : x From ffb37b81c69036ed9ef8e8ec46060beb19e055ae Mon Sep 17 00:00:00 2001 From: pavan-msys Date: Thu, 15 May 2025 07:18:55 +0530 Subject: [PATCH 3/5] updated tests --- .../aggregation/test_aggregation_filtering.mmd} | 4 +--- .../aggregation}/test_aggregation_filtering.py | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) rename tests/{functional/t/test_aggregation_filtering.txt => pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd} (69%) rename tests/{functional/t => pyreverse/functional/class_diagrams/aggregation}/test_aggregation_filtering.py (53%) diff --git a/tests/functional/t/test_aggregation_filtering.txt b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd similarity index 69% rename from tests/functional/t/test_aggregation_filtering.txt rename to tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd index f51d6cbaec..27ca0db48f 100644 --- a/tests/functional/t/test_aggregation_filtering.txt +++ b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd @@ -4,8 +4,6 @@ classDiagram } class B { } - class C { - } class P { } - P --* A : x + P --* A : x \ No newline at end of file diff --git a/tests/functional/t/test_aggregation_filtering.py b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py similarity index 53% rename from tests/functional/t/test_aggregation_filtering.py rename to tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py index b2c898906b..8c87070f33 100644 --- a/tests/functional/t/test_aggregation_filtering.py +++ b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py @@ -1,3 +1,5 @@ +# Test for https://github.com/pylint-dev/pylint/issues/10373 + class P: pass @@ -6,6 +8,3 @@ class A: class B: __x: P = P() - -class C: - _y: P = P() From 6d71390129e746cf5aaa69eefe74da11bb79627b Mon Sep 17 00:00:00 2001 From: pavan-msys Date: Mon, 19 May 2025 16:38:20 +0530 Subject: [PATCH 4/5] added test cases --- .../test_aggregation_filtering.mmd | 9 ------- .../aggregation/test_aggregation_filtering.py | 10 -------- .../aggregation_filtering/all.mmd | 25 +++++++++++++++++++ .../aggregation_filtering/all.py | 23 +++++++++++++++++ .../aggregation_filtering/all.rc | 2 ++ .../aggregation_filtering/other.mmd | 21 ++++++++++++++++ .../aggregation_filtering/other.py | 23 +++++++++++++++++ .../aggregation_filtering/other.rc | 2 ++ .../aggregation_filtering/pub_only.mmd | 14 +++++++++++ .../aggregation_filtering/pub_only.py | 23 +++++++++++++++++ .../aggregation_filtering/pub_only.rc | 2 ++ .../aggregation_filtering/special.mmd | 18 +++++++++++++ .../aggregation_filtering/special.py | 23 +++++++++++++++++ .../aggregation_filtering/special.rc | 2 ++ 14 files changed, 178 insertions(+), 19 deletions(-) delete mode 100644 tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd delete mode 100644 tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.py create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.py create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.rc create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.py create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.rc create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.mmd create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.py create mode 100644 tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.rc diff --git a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd deleted file mode 100644 index 27ca0db48f..0000000000 --- a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.mmd +++ /dev/null @@ -1,9 +0,0 @@ -classDiagram - class A { - x - } - class B { - } - class P { - } - P --* A : x \ No newline at end of file diff --git a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py b/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py deleted file mode 100644 index 8c87070f33..0000000000 --- a/tests/pyreverse/functional/class_diagrams/aggregation/test_aggregation_filtering.py +++ /dev/null @@ -1,10 +0,0 @@ -# Test for https://github.com/pylint-dev/pylint/issues/10373 - -class P: - pass - -class A: - x: P = P() - -class B: - __x: P = P() diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.mmd b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.mmd new file mode 100644 index 0000000000..3b445288a1 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.mmd @@ -0,0 +1,25 @@ +classDiagram + class P { + name : str + __init__(name: str) + } + class PrivateAttr { + __x + __init__() + } + class ProtectedAttr { + _x + __init__() + } + class PublicAttr { + x + __init__() + } + class SpecialAttr { + __x__ + __init__() + } + P --* PrivateAttr : __x + P --* ProtectedAttr : _x + P --* PublicAttr : x + P --* SpecialAttr : __x__ diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.py b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.py new file mode 100644 index 0000000000..609f4376be --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.py @@ -0,0 +1,23 @@ +class P: + def __init__(self, name: str): + self.name = name + + +class PrivateAttr: + def __init__(self): + self.__x = P("private") + + +class ProtectedAttr: + def __init__(self): + self._x = P("protected") + + +class PublicAttr: + def __init__(self): + self.x = P("public") + + +class SpecialAttr: + def __init__(self): + self.__x__ = P("special") diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc new file mode 100644 index 0000000000..43bbc072c6 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc @@ -0,0 +1,2 @@ +[testoptions] +command_line_args=--filter-mode=ALL \ No newline at end of file diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.mmd b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.mmd new file mode 100644 index 0000000000..6cfcae244f --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.mmd @@ -0,0 +1,21 @@ +classDiagram + class P { + name : str + __init__(name: str) + } + class PrivateAttr { + __init__() + } + class ProtectedAttr { + __init__() + } + class PublicAttr { + x + __init__() + } + class SpecialAttr { + __x__ + __init__() + } + P --* PublicAttr : x + P --* SpecialAttr : __x__ diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.py b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.py new file mode 100644 index 0000000000..609f4376be --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.py @@ -0,0 +1,23 @@ +class P: + def __init__(self, name: str): + self.name = name + + +class PrivateAttr: + def __init__(self): + self.__x = P("private") + + +class ProtectedAttr: + def __init__(self): + self._x = P("protected") + + +class PublicAttr: + def __init__(self): + self.x = P("public") + + +class SpecialAttr: + def __init__(self): + self.__x__ = P("special") diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.rc b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.rc new file mode 100644 index 0000000000..8e0e615079 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/other.rc @@ -0,0 +1,2 @@ +[testoptions] +command_line_args=--filter-mode=OTHER diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.mmd b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.mmd new file mode 100644 index 0000000000..f29000b5c8 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.mmd @@ -0,0 +1,14 @@ +classDiagram + class P { + name : str + } + class PrivateAttr { + } + class ProtectedAttr { + } + class PublicAttr { + x + } + class SpecialAttr { + } + P --* PublicAttr : x diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.py b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.py new file mode 100644 index 0000000000..609f4376be --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.py @@ -0,0 +1,23 @@ +class P: + def __init__(self, name: str): + self.name = name + + +class PrivateAttr: + def __init__(self): + self.__x = P("private") + + +class ProtectedAttr: + def __init__(self): + self._x = P("protected") + + +class PublicAttr: + def __init__(self): + self.x = P("public") + + +class SpecialAttr: + def __init__(self): + self.__x__ = P("special") diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.rc b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.rc new file mode 100644 index 0000000000..4dddc11448 --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/pub_only.rc @@ -0,0 +1,2 @@ +[testoptions] +command_line_args=--filter-mode=PUB_ONLY diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.mmd b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.mmd new file mode 100644 index 0000000000..149b0a694a --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.mmd @@ -0,0 +1,18 @@ +classDiagram + class P { + name : str + } + class PrivateAttr { + __x + } + class ProtectedAttr { + _x + } + class PublicAttr { + x + } + class SpecialAttr { + } + P --* PrivateAttr : __x + P --* ProtectedAttr : _x + P --* PublicAttr : x diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.py b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.py new file mode 100644 index 0000000000..609f4376be --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.py @@ -0,0 +1,23 @@ +class P: + def __init__(self, name: str): + self.name = name + + +class PrivateAttr: + def __init__(self): + self.__x = P("private") + + +class ProtectedAttr: + def __init__(self): + self._x = P("protected") + + +class PublicAttr: + def __init__(self): + self.x = P("public") + + +class SpecialAttr: + def __init__(self): + self.__x__ = P("special") diff --git a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.rc b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.rc new file mode 100644 index 0000000000..4e60bfdf4d --- /dev/null +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/special.rc @@ -0,0 +1,2 @@ +[testoptions] +command_line_args=--filter-mode=SPECIAL From bdfe1076fc51a3a3e3bd32ac1460c337f44257de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 11:09:49 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/whatsnew/fragments/10373.bugfix | 2 +- pylint/pyreverse/diagrams.py | 4 ++-- .../functional/class_diagrams/aggregation_filtering/all.rc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/whatsnew/fragments/10373.bugfix b/doc/whatsnew/fragments/10373.bugfix index 59310028c2..d7ba3a1893 100644 --- a/doc/whatsnew/fragments/10373.bugfix +++ b/doc/whatsnew/fragments/10373.bugfix @@ -1,3 +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 \ No newline at end of file +Closes #10373 diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index fd3f616739..a4fb8ce130 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -239,7 +239,7 @@ def extract_relationships(self) -> None: for value in values: if not self.show_attr(name): continue - + self.assign_association_relationship( value, obj, name, "aggregation" ) @@ -254,7 +254,7 @@ def extract_relationships(self) -> None: 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_filtering/all.rc b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc index 43bbc072c6..08fbb3d02d 100644 --- a/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc +++ b/tests/pyreverse/functional/class_diagrams/aggregation_filtering/all.rc @@ -1,2 +1,2 @@ [testoptions] -command_line_args=--filter-mode=ALL \ No newline at end of file +command_line_args=--filter-mode=ALL