-
-
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
Apply infer_kwarg_from_call()
to more checks
#8775
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Apply ``infer_kwarg_from_call()`` to more checks | ||
|
||
These mostly solve false negatives for various checks, | ||
save for one false positive for ``use-maxsplit-arg``. | ||
|
||
Closes #7761 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2203,12 +2203,14 @@ def _check_unnecessary_list_index_lookup( | |
): | ||
return | ||
|
||
preliminary_confidence = HIGH | ||
try: | ||
iterable_arg = utils.get_argument_from_call( | ||
node.iter, position=0, keyword="iterable" | ||
) | ||
except utils.NoSuchArgumentError: | ||
return | ||
iterable_arg = utils.infer_kwarg_from_call(node.iter, keyword="iterable") | ||
preliminary_confidence = INFERENCE | ||
|
||
if not isinstance(iterable_arg, nodes.Name): | ||
return | ||
|
@@ -2228,6 +2230,13 @@ def _check_unnecessary_list_index_lookup( | |
# is not redundant, hence we should not report an error. | ||
return | ||
|
||
# Preserve preliminary_confidence if it was INFERENCE | ||
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. Not terribly important, but maybe someday a 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. What about a 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. It should just wait for #7121, when we might have a numeric level we can just compare directly. |
||
confidence = ( | ||
preliminary_confidence | ||
if preliminary_confidence == INFERENCE | ||
else confidence | ||
) | ||
|
||
iterating_object_name = iterable_arg.name | ||
value_variable = node.target.elts[1] | ||
|
||
|
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.
At this point it's not preliminary anymore so it c/sould be named confidence ?
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.
It is preliminary if the second one turns out to be CONTROL_FLOW, was my thought. But then I should change the second condition to != HIGH.
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.
Well, that's not quite right either. I guess I'd rather keep preliminary for now.