Skip to content

Commit

Permalink
Fix duplicate fields Pyreverse bug (#9004) (#9011)
Browse files Browse the repository at this point in the history
(cherry picked from commit 022988a)

Co-authored-by: Nick Drozd <nicholasdrozd@gmail.com>
  • Loading branch information
github-actions[bot] and nickdrozd authored Sep 6, 2023
1 parent 6da1d5a commit 79aac5b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8189.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Don't show class fields more than once in Pyreverse diagrams.

Closes #8189
21 changes: 12 additions & 9 deletions pylint/pyreverse/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ classDiagram
}
class DuplicateArrows {
a
a
}
class DuplicateFields {
example1 : int
example1 : int
example2 : int
example2 : int
}
A --* DuplicateArrows : a
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 79aac5b

Please sign in to comment.