From 094a774285378901034e01fde97a43d861c1dfa1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 19:34:12 +0000 Subject: [PATCH] Fix Pyreverse duplicate annotations (#9012) (#9017) (cherry picked from commit fbbf7880b2e55673bb0e4ba0b1c6c06ca677d5d6) Co-authored-by: Nick Drozd --- doc/whatsnew/fragments/8888.bugfix | 3 +++ pylint/pyreverse/diagrams.py | 6 +++++- .../functional/class_diagrams/attributes/duplicates.mmd | 4 ++-- .../functional/class_diagrams/attributes/duplicates.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 doc/whatsnew/fragments/8888.bugfix 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"