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 2 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
16 changes: 9 additions & 7 deletions pylint/pyreverse/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ def get_relationship(
def get_attrs(self, node: nodes.ClassDef) -> list[str]:
"""Return visible attributes, possibly with class name."""
attrs = []
properties = [
(n, m)
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
}
for n, m in list(node.locals_type.items()) + list(
node.instance_attrs_type.items()
):
if n not in properties:
properties[n] = m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use explicit name instead, I don't know what n/m is and I took 30s to try to come up with a proper suggestion: definitely a read blocker πŸ˜„

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure what m is, so I went with name and attr.


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
# FIXED: https://github.com/pylint-dev/pylint/issues/8189
class DuplicateFields():
nickdrozd marked this conversation as resolved.
Show resolved Hide resolved
example1: int
example2: int
Expand Down
Loading