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(consider-interating-dictionary): fix false negatives #5331

Merged
merged 8 commits into from Nov 30, 2021

Conversation

yushao2
Copy link
Collaborator

@yushao2 yushao2 commented Nov 17, 2021

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Added loop logic to check upwards (parents of node) until i hit a compare node, to circumvent the issue where list(dict.keys()) results in the node.parent to be of type call

Also, added operator check for not in

Closes #5323

@coveralls
Copy link

coveralls commented Nov 17, 2021

Pull Request Test Coverage Report for Build 1513154202

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 93.507%

Totals Coverage Status
Change from base Build 1513087577: 0.003%
Covered Lines: 13998
Relevant Lines: 14970

πŸ’› - Coveralls

@yushao2 yushao2 force-pushed the fix--false-negative-5323 branch 2 times, most recently from 155ce7c to 08884a6 Compare November 17, 2021 17:57
@yushao2 yushao2 added the Needs review πŸ” Needs to be reviewed by one or multiple more persons label Nov 17, 2021
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution!

We have currently closed 2.12 as we're trying to finalise that release, but this should definitely go in 2.13. We will need to update the place of the changelog entry when we can (after release of 2.12).

ChangeLog Outdated Show resolved Hide resolved
doc/whatsnew/2.12.rst Outdated Show resolved Hide resolved
pylint/checkers/refactoring/recommendation_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/recommendation_checker.py Outdated Show resolved Hide resolved
@DanielNoord DanielNoord added Enhancement ✨ Improvement to a component False Negative πŸ¦‹ No message is emitted but something is wrong with the code labels Nov 17, 2021
@DanielNoord DanielNoord added this to the 2.13.0 milestone Nov 17, 2021
@Pierre-Sassoulas
Copy link
Member

Nice to see a new contribution from you @yushao2 :)

@yushao2
Copy link
Collaborator Author

yushao2 commented Nov 18, 2021

Nice to see a new contribution from you @yushao2 :)

great to be back, had a hard time adjusting to my new role as devops but slowly getting the hang of it (and thus more room to breathe and to contribute :D)

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

This is really quite elegant! Thanks for the quick work πŸ˜„

pylint/checkers/utils.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/recommendation_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/recommendation_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/recommendation_checker.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Looks good except for the set membership test. Thanks for this!

@DanielNoord DanielNoord added Blocked 🚧 Blocked by a particular issue and removed Needs review πŸ” Needs to be reviewed by one or multiple more persons labels Nov 19, 2021
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.

Nice changes thank you @yushao2 ! I request change so we remember to move the changelog to 2.13 before merging.

yushao2 and others added 7 commits November 29, 2021 00:25
Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
@yushao2 yushao2 added Needs review πŸ” Needs to be reviewed by one or multiple more persons and removed Blocked 🚧 Blocked by a particular issue labels Nov 28, 2021
@DanielNoord DanielNoord added Blocked 🚧 Blocked by a particular issue and removed Needs review πŸ” Needs to be reviewed by one or multiple more persons labels Nov 28, 2021
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.

Small change, big result πŸ‘

@yushao2 yushao2 merged commit 6caab13 into pylint-dev:main Nov 30, 2021
@DanielNoord
Copy link
Collaborator

DanielNoord commented Nov 30, 2021

@yushao2 Note that this PR was/is blocked by the release of 2.12.2 and the Changelog entry in this PR is still in 2.12. It should either be 2.12.2 or 2.13. The other PR is also blocked!

@Pierre-Sassoulas
Copy link
Member

Don't worry about this one, I'll fix the changelog when releasing 2.12.2

@DanielNoord DanielNoord modified the milestones: 2.13.0, 2.12.2 Nov 30, 2021
@DanielNoord DanielNoord removed the Blocked 🚧 Blocked by a particular issue label Nov 30, 2021
@yushao2
Copy link
Collaborator Author

yushao2 commented Nov 30, 2021

That is my bad, i got confused. Sorry for the trouble

Comment on lines +1698 to +1700
def get_node_first_ancestor_of_type(
node: nodes.NodeNG, ancestor_type: Tuple[Type[T_Node]]
) -> Optional[T_Node]:
Copy link
Member

Choose a reason for hiding this comment

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

Don't know if that has been considered. There is no need to limit ancestor_type to Tuple[...]. isinstance works fine with Type[T_Node] too. Ie.

ancestor_type: Union[Type[T_Node], Tuple[Type[T_Node]]]

This has the advantage that now you can pass both a single type and a tuple of types to it.

@@ -83,21 +83,22 @@ def _check_consider_iterating_dictionary(self, node: nodes.Call) -> None:
return
if node.func.attrname != "keys":
return
comp_ancestor = utils.get_node_first_ancestor_of_type(node, (nodes.Compare,))
Copy link
Member

Choose a reason for hiding this comment

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

comp_ancestor = utils.get_node_first_ancestor_of_type(node, nodes.Compare)

This could then be simplified.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added to #5447 as a follow up issue to this.

I initially wanted to keep the typing of the function simple so thought it would be okay to only allow tuples, but we could allow both.

@yushao2 yushao2 deleted the fix--false-negative-5323 branch January 4, 2023 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative for consider-iterating-dictionary when using not or list
5 participants