Skip to content

Commit

Permalink
Fix Pyreverse duplicate annotations (#9012) (#9017)
Browse files Browse the repository at this point in the history
(cherry picked from commit fbbf788)

Co-authored-by: Nick Drozd <nicholasdrozd@gmail.com>
  • Loading branch information
github-actions[bot] and nickdrozd committed Sep 7, 2023
1 parent 79aac5b commit 094a774
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8888.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Don't show duplicate type annotations in Pyreverse diagrams.

Closes #8888
6 changes: 5 additions & 1 deletion pylint/pyreverse/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ def class_names(self, nodes_lst: Iterable[nodes.NodeNG]) -> list[str]:
node_name = node.name
names.append(node_name)
# sorted to get predictable (hence testable) results
return sorted(names)
return sorted(
name
for name in names
if all(name not in other or name == other for other in names)
)

def has_node(self, node: nodes.NodeNG) -> bool:
"""Return true if the given node is included in the diagram."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ classDiagram
class A {
}
class DuplicateAnnotations {
lav : list, list[str]
val : str, str | int
lav : list[str]
val : str | int
bar() None
}
class DuplicateArrows {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):



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

0 comments on commit 094a774

Please sign in to comment.