-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
be257fe
fix(consider-interating-dictionary): fix false negatives
yushao2 2b3ed7e
Apply suggestions from code review
yushao2 554801a
added util functions and changed code according to pr comments
yushao2 ccd2974
Apply suggestions from code review
yushao2 507c502
update code based on code review
yushao2 0ec1975
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 39fb9eb
Update pylint/checkers/refactoring/recommendation_checker.py
yushao2 03bae75
chore(*): moved changelog entry from 2.12 to 2.13
yushao2 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ | |
Set, | ||
Tuple, | ||
Type, | ||
TypeVar, | ||
Union, | ||
) | ||
|
||
|
@@ -280,6 +281,8 @@ | |
) | ||
) | ||
|
||
T_Node = TypeVar("T_Node", bound=nodes.NodeNG) | ||
|
||
|
||
class NoSuchArgumentError(Exception): | ||
pass | ||
|
@@ -1690,3 +1693,13 @@ def returns_bool(node: nodes.NodeNG) -> bool: | |
and isinstance(node.value, nodes.Const) | ||
and node.value.value in {True, False} | ||
) | ||
|
||
|
||
def get_node_first_ancestor_of_type( | ||
node: nodes.NodeNG, ancestor_type: Tuple[Type[T_Node]] | ||
) -> Optional[T_Node]: | ||
Comment on lines
+1698
to
+1700
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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. |
||
"""Return the first parent node that is any of the provided types (or None)""" | ||
for ancestor in node.node_ancestors(): | ||
if isinstance(ancestor, ancestor_type): | ||
return ancestor | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.