Skip to content

Commit

Permalink
Fix duplicate fields Pyreverse bug (#9004)
Browse files Browse the repository at this point in the history
* Fix duplicate fields

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
nickdrozd and pre-commit-ci[bot] authored Sep 6, 2023
1 parent 9c1c663 commit 022988a
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 @@ -121,16 +121,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 022988a

Please sign in to comment.