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

Conversation

nickdrozd
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #8189

@nickdrozd nickdrozd added the pyreverse Related to pyreverse component label Sep 4, 2023
@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

Merging #9004 (306e454) into main (9d59adc) will decrease coverage by 0.02%.
Report is 10 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9004      +/-   ##
==========================================
- Coverage   95.76%   95.75%   -0.02%     
==========================================
  Files         173      173              
  Lines       18639    18648       +9     
==========================================
+ Hits        17850    17856       +6     
- Misses        789      792       +3     
Files Changed Coverage Ξ”
pylint/pyreverse/diagrams.py 93.22% <100.00%> (+0.11%) ⬆️

... and 2 files with indirect coverage changes

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Some nits, looks like a proper fix otherwise :)

Comment on lines 129 to 133
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.

@Pierre-Sassoulas
Copy link
Member

Also not sure if we backported the tests previously so we can't backport to 2.17.6 afaik (unless we also backport the prior PR which is still possible). Added to the 3.0.0a8 milestone because it might not be that important.

DudeNr33
DudeNr33 previously approved these changes Sep 4, 2023
Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

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

I agree with Pierre and the wish for more explicit names, but I also have nothing more to add. Thanks!

We did not backport the PR with the tests yet. I'd say if 3.0 is going to be released soon(ish) we don't need to, but if it's going to take a few more months we can backport, as it is also not a big code change.

@Pierre-Sassoulas
Copy link
Member

Realistically 3.0 could be released far in the future, I'm going to backport #8983 (especially since it should just a label to apply)

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Sep 4, 2023

Thanks!

+ properties
properties = {
name: attr
for name, attr in node.items()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had to look into the code as well, but as I see it:

Here, node is of type nodes.ClassDef, and node.items() is a mapping from local name to the node defining the local:
https://github.com/pylint-dev/astroid/blob/600229f5dbe29ce9074b3c76a9d195951cb561a4/astroid/nodes/scoped_nodes/mixin.py#L179-L180

Thus for local_name, local_node in node.items() would be best IMO.

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

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

I left two comments regarding the naming. But I had to take a closer look into the code myself as well. πŸ˜„

Comment on lines 129 to 130
for name, attr in list(node.locals_type.items()) + list(
node.instance_attrs_type.items()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, locals_type and instance_attrs_type are mappings from attribute name to possible types (from annotations or inference results), so for attr_name, attr_type in ... would be better.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 306e454

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

LGTM, I'll let @DudeNr33 merge.

@DudeNr33 DudeNr33 merged commit 022988a into pylint-dev:main Sep 6, 2023
42 checks passed
@DudeNr33
Copy link
Collaborator

DudeNr33 commented Sep 6, 2023

πŸš€

github-actions bot pushed a commit that referenced this pull request Sep 6, 2023
* Fix duplicate fields

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 022988a)
Pierre-Sassoulas pushed a commit that referenced this pull request Sep 6, 2023
(cherry picked from commit 022988a)

Co-authored-by: Nick Drozd <[email protected]>
@nickdrozd nickdrozd deleted the duplicate-fields branch September 6, 2023 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Bug πŸͺ² pyreverse Related to pyreverse component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pyreverse should ignore class level attribute declarations
3 participants