diff --git a/doc/whatsnew/fragments/8189.bugfix b/doc/whatsnew/fragments/8189.bugfix new file mode 100644 index 0000000000..b7d3460567 --- /dev/null +++ b/doc/whatsnew/fragments/8189.bugfix @@ -0,0 +1,3 @@ +Don't show class fields more than once in Pyreverse diagrams. + +Closes #8189 diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 543467e9d5..804782f536 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -115,16 +115,19 @@ def get_relationship( def get_attrs(self, node: nodes.ClassDef) -> list[str]: """Return visible attributes, possibly with class name.""" attrs = [] - properties = [ - (n, m) - for n, m in node.items() - if isinstance(m, nodes.FunctionDef) and decorated_with_property(m) - ] - for node_name, associated_nodes in ( - list(node.instance_attrs_type.items()) - + list(node.locals_type.items()) - + properties + properties = { + local_name: local_node + for local_name, local_node in node.items() + if isinstance(local_node, nodes.FunctionDef) + and decorated_with_property(local_node) + } + for attr_name, attr_type in list(node.locals_type.items()) + list( + node.instance_attrs_type.items() ): + if attr_name not in properties: + properties[attr_name] = attr_type + + for node_name, associated_nodes in properties.items(): if not self.show_attr(node_name): continue names = self.class_names(associated_nodes) diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd index ee13b83462..71a59b33e9 100644 --- a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd @@ -8,12 +8,9 @@ classDiagram } class DuplicateArrows { a - a } class DuplicateFields { example1 : int - example1 : int - example2 : int example2 : int } A --* DuplicateArrows : a diff --git a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py index a3f05b81cb..586329b20a 100644 --- a/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py +++ b/tests/pyreverse/functional/class_diagrams/attributes/duplicates.py @@ -1,4 +1,4 @@ -# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8189 +# Test for https://github.com/pylint-dev/pylint/issues/8189 class DuplicateFields(): example1: int example2: int