Skip to content

Commit 79aac5b

Browse files
Fix duplicate fields Pyreverse bug (#9004) (#9011)
(cherry picked from commit 022988a) Co-authored-by: Nick Drozd <nicholasdrozd@gmail.com>
1 parent 6da1d5a commit 79aac5b

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

doc/whatsnew/fragments/8189.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Don't show class fields more than once in Pyreverse diagrams.
2+
3+
Closes #8189

pylint/pyreverse/diagrams.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,19 @@ def get_relationship(
115115
def get_attrs(self, node: nodes.ClassDef) -> list[str]:
116116
"""Return visible attributes, possibly with class name."""
117117
attrs = []
118-
properties = [
119-
(n, m)
120-
for n, m in node.items()
121-
if isinstance(m, nodes.FunctionDef) and decorated_with_property(m)
122-
]
123-
for node_name, associated_nodes in (
124-
list(node.instance_attrs_type.items())
125-
+ list(node.locals_type.items())
126-
+ properties
118+
properties = {
119+
local_name: local_node
120+
for local_name, local_node in node.items()
121+
if isinstance(local_node, nodes.FunctionDef)
122+
and decorated_with_property(local_node)
123+
}
124+
for attr_name, attr_type in list(node.locals_type.items()) + list(
125+
node.instance_attrs_type.items()
127126
):
127+
if attr_name not in properties:
128+
properties[attr_name] = attr_type
129+
130+
for node_name, associated_nodes in properties.items():
128131
if not self.show_attr(node_name):
129132
continue
130133
names = self.class_names(associated_nodes)

tests/pyreverse/functional/class_diagrams/attributes/duplicates.mmd

-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ classDiagram
88
}
99
class DuplicateArrows {
1010
a
11-
a
1211
}
1312
class DuplicateFields {
1413
example1 : int
15-
example1 : int
16-
example2 : int
1714
example2 : int
1815
}
1916
A --* DuplicateArrows : a

tests/pyreverse/functional/class_diagrams/attributes/duplicates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OPEN BUG: https://github.com/pylint-dev/pylint/issues/8189
1+
# Test for https://github.com/pylint-dev/pylint/issues/8189
22
class DuplicateFields():
33
example1: int
44
example2: int

0 commit comments

Comments
 (0)