Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate fields Pyreverse bug #9004

Merged
merged 5 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading