Skip to content

Commit ed59632

Browse files
Fix Pyreverse: Aggregations aren't filtered according to filter mode (PUB_ONLY, etc.) (#10379)
* updated diagrams.py file * added tests * updated tests * added test cases * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6e04d16 commit ed59632

File tree

14 files changed

+187
-0
lines changed

14 files changed

+187
-0
lines changed

doc/whatsnew/fragments/10373.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
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.).
2+
3+
Closes #10373

pylint/pyreverse/diagrams.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ def extract_relationships(self) -> None:
237237
# associations & aggregations links
238238
for name, values in list(node.aggregations_type.items()):
239239
for value in values:
240+
if not self.show_attr(name):
241+
continue
242+
240243
self.assign_association_relationship(
241244
value, obj, name, "aggregation"
242245
)
@@ -249,6 +252,9 @@ def extract_relationships(self) -> None:
249252

250253
for name, values in associations.items():
251254
for value in values:
255+
if not self.show_attr(name):
256+
continue
257+
252258
self.assign_association_relationship(
253259
value, obj, name, "association"
254260
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classDiagram
2+
class P {
3+
name : str
4+
__init__(name: str)
5+
}
6+
class PrivateAttr {
7+
__x
8+
__init__()
9+
}
10+
class ProtectedAttr {
11+
_x
12+
__init__()
13+
}
14+
class PublicAttr {
15+
x
16+
__init__()
17+
}
18+
class SpecialAttr {
19+
__x__
20+
__init__()
21+
}
22+
P --* PrivateAttr : __x
23+
P --* ProtectedAttr : _x
24+
P --* PublicAttr : x
25+
P --* SpecialAttr : __x__
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class P:
2+
def __init__(self, name: str):
3+
self.name = name
4+
5+
6+
class PrivateAttr:
7+
def __init__(self):
8+
self.__x = P("private")
9+
10+
11+
class ProtectedAttr:
12+
def __init__(self):
13+
self._x = P("protected")
14+
15+
16+
class PublicAttr:
17+
def __init__(self):
18+
self.x = P("public")
19+
20+
21+
class SpecialAttr:
22+
def __init__(self):
23+
self.__x__ = P("special")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
command_line_args=--filter-mode=ALL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
classDiagram
2+
class P {
3+
name : str
4+
__init__(name: str)
5+
}
6+
class PrivateAttr {
7+
__init__()
8+
}
9+
class ProtectedAttr {
10+
__init__()
11+
}
12+
class PublicAttr {
13+
x
14+
__init__()
15+
}
16+
class SpecialAttr {
17+
__x__
18+
__init__()
19+
}
20+
P --* PublicAttr : x
21+
P --* SpecialAttr : __x__
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class P:
2+
def __init__(self, name: str):
3+
self.name = name
4+
5+
6+
class PrivateAttr:
7+
def __init__(self):
8+
self.__x = P("private")
9+
10+
11+
class ProtectedAttr:
12+
def __init__(self):
13+
self._x = P("protected")
14+
15+
16+
class PublicAttr:
17+
def __init__(self):
18+
self.x = P("public")
19+
20+
21+
class SpecialAttr:
22+
def __init__(self):
23+
self.__x__ = P("special")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
command_line_args=--filter-mode=OTHER
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
classDiagram
2+
class P {
3+
name : str
4+
}
5+
class PrivateAttr {
6+
}
7+
class ProtectedAttr {
8+
}
9+
class PublicAttr {
10+
x
11+
}
12+
class SpecialAttr {
13+
}
14+
P --* PublicAttr : x
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class P:
2+
def __init__(self, name: str):
3+
self.name = name
4+
5+
6+
class PrivateAttr:
7+
def __init__(self):
8+
self.__x = P("private")
9+
10+
11+
class ProtectedAttr:
12+
def __init__(self):
13+
self._x = P("protected")
14+
15+
16+
class PublicAttr:
17+
def __init__(self):
18+
self.x = P("public")
19+
20+
21+
class SpecialAttr:
22+
def __init__(self):
23+
self.__x__ = P("special")

0 commit comments

Comments
 (0)