diff --git a/doc/whatsnew/fragments/8888.bugfix b/doc/whatsnew/fragments/8888.bugfix new file mode 100644 index 0000000000..7208a46493 --- /dev/null +++ b/doc/whatsnew/fragments/8888.bugfix @@ -0,0 +1,3 @@ +Don't show duplicate type annotations in Pyreverse diagrams. + +Closes #8888 diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 804782f536..3d668f6487 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -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.""" diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd index 71a59b33e9..9e1224314c 100644 --- a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd @@ -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 { diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py index 586329b20a..78bec08af1 100644 --- a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py @@ -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"