Skip to content

Commit fbbf788

Browse files
authored
Fix Pyreverse duplicate annotations (#9012)
1 parent 20fa209 commit fbbf788

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

doc/whatsnew/fragments/8888.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Don't show duplicate type annotations in Pyreverse diagrams.
2+
3+
Closes #8888

pylint/pyreverse/diagrams.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ def class_names(self, nodes_lst: Iterable[nodes.NodeNG]) -> list[str]:
178178
node_name = node.name
179179
names.append(node_name)
180180
# sorted to get predictable (hence testable) results
181-
return sorted(names)
181+
return sorted(
182+
name
183+
for name in names
184+
if all(name not in other or name == other for other in names)
185+
)
182186

183187
def has_node(self, node: nodes.NodeNG) -> bool:
184188
"""Return true if the given node is included in the diagram."""

tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ classDiagram
22
class A {
33
}
44
class DuplicateAnnotations {
5-
lav : list, list[str]
6-
val : str, str | int
5+
lav : list[str]
6+
val : str | int
77
bar() None
88
}
99
class DuplicateArrows {

tests/pyreverse/functional/class_diagrams/attributes/duplicates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self):
2020

2121

2222

23-
# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8888
23+
# Test for https://github.com/pylint-dev/pylint/issues/8888
2424
class DuplicateAnnotations:
2525
def __init__(self) -> None:
2626
self.val: str | int = "1"

0 commit comments

Comments
 (0)