-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Pull Request Test Coverage Report for Build 1513154202
π - Coveralls |
155ce7c
to
08884a6
Compare
There was a problem hiding this 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
).
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) |
There was a problem hiding this 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 π
There was a problem hiding this 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!
There was a problem hiding this 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.
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>
for more information, see https://pre-commit.ci
Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
362e280
to
7dab24d
Compare
7dab24d
to
03bae75
Compare
There was a problem hiding this 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 Note that this PR was/is blocked by the release of |
Don't worry about this one, I'll fix the changelog when releasing 2.12.2 |
That is my bad, i got confused. Sorry for the trouble |
def get_node_first_ancestor_of_type( | ||
node: nodes.NodeNG, ancestor_type: Tuple[Type[T_Node]] | ||
) -> Optional[T_Node]: |
There was a problem hiding this comment.
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,)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Type of Changes
Description
Added loop logic to check upwards (parents of node) until i hit a
compare
node, to circumvent the issue wherelist(dict.keys())
results in thenode.parent
to be of typecall
Also, added operator check for
not in
Closes #5323