Skip to content

Commit 094a774

Browse files
Fix Pyreverse duplicate annotations (#9012) (#9017)
(cherry picked from commit fbbf788) Co-authored-by: Nick Drozd <[email protected]>
1 parent 79aac5b commit 094a774

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
@@ -172,7 +172,11 @@ def class_names(self, nodes_lst: Iterable[nodes.NodeNG]) -> list[str]:
172172
node_name = node.name
173173
names.append(node_name)
174174
# sorted to get predictable (hence testable) results
175-
return sorted(names)
175+
return sorted(
176+
name
177+
for name in names
178+
if all(name not in other or name == other for other in names)
179+
)
176180

177181
def has_node(self, node: nodes.NodeNG) -> bool:
178182
"""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)