Skip to content

Commit

Permalink
too-few-function-args redundant with no-value-for-parameter (#9882)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
rogersheu and Pierre-Sassoulas authored Aug 19, 2024
1 parent a32250c commit 40f58ea
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 34 deletions.
1 change: 0 additions & 1 deletion doc/data/messages/t/too-few-function-args/bad.py

This file was deleted.

2 changes: 0 additions & 2 deletions doc/data/messages/t/too-few-function-args/details.rst

This file was deleted.

1 change: 0 additions & 1 deletion doc/data/messages/t/too-few-function-args/good.py

This file was deleted.

2 changes: 0 additions & 2 deletions doc/user_guide/checkers/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,6 @@ Typecheck checker Messages
:invalid-slice-step (E1144): *Slice step cannot be 0*
Used when a slice step is 0 and the object doesn't implement a custom
__getitem__ method.
:too-few-function-args (E1145): *Too few positional arguments for %s call*
Used when a function or method call has fewer arguments than expected.
:too-many-function-args (E1121): *Too many positional arguments for %s call*
Used when a function call passes too many positional arguments.
:unexpected-keyword-arg (E1123): *Unexpected keyword argument %r in %s call*
Expand Down
1 change: 0 additions & 1 deletion doc/user_guide/messages/messages_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ All messages in the error category:
error/star-needs-assignment-target
error/syntax-error
error/too-few-format-args
error/too-few-function-args
error/too-many-format-args
error/too-many-function-args
error/too-many-star-expressions
Expand Down
6 changes: 3 additions & 3 deletions doc/whatsnew/fragments/9847.false_negative
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Fix a false negative when `isinstance` has too many arguments.
Change now emits a `too-many-function-args` output with behavior similar to other
`too-many-function-args` calls.
Fix false negatives when `isinstance` does not have exactly two arguments.
pylint now emits a `too-many-function-args` or `no-value-for-parameter`
appropriately for `isinstance` calls.

Closes #9847
5 changes: 0 additions & 5 deletions doc/whatsnew/fragments/9847.new_check

This file was deleted.

22 changes: 11 additions & 11 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ def _missing_member_hint(
"Used when a slice step is 0 and the object doesn't implement "
"a custom __getitem__ method.",
),
"E1145": (
"Too few positional arguments for %s call",
"too-few-function-args",
"Used when a function or method call has fewer arguments than expected.",
),
"W1113": (
"Keyword argument before variable positional arguments list "
"in the definition of %s function",
Expand Down Expand Up @@ -1434,12 +1429,17 @@ def _check_isinstance_args(self, node: nodes.Call, callable_name: str) -> None:
confidence=HIGH,
)
elif len(node.args) < 2:
self.add_message(
"too-few-function-args",
node=node,
args=(callable_name,),
confidence=HIGH,
)
# NOTE: Hard-coding the parameters for `isinstance` is fragile,
# but as noted elsewhere, built-in functions do not provide
# argument info, making this necessary for now.
parameters = ("'_obj'", "'__class_or_tuple'")
for parameter in parameters[len(node.args) :]:
self.add_message(
"no-value-for-parameter",
node=node,
args=(parameter, callable_name),
confidence=HIGH,
)
return

second_arg = node.args[1]
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/a/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,5 @@ def func(string):

func(42)
a = func(42)

isinstance(1) # [no-value-for-parameter]
1 change: 1 addition & 0 deletions tests/functional/a/arguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ no-value-for-parameter:217:0:217:30::No value for argument 'second' in function
unexpected-keyword-arg:218:0:218:43::Unexpected keyword argument 'fourth' in function call:UNDEFINED
redundant-keyword-arg:308:0:308:79::Argument 'banana' passed by position and keyword in function call:UNDEFINED
no-value-for-parameter:318:0:318:16::No value for argument 'param1' in function call:UNDEFINED
no-value-for-parameter:335:0:335:13::No value for argument '__class_or_tuple' in function call:HIGH
4 changes: 2 additions & 2 deletions tests/functional/c/consider/consider_merging_isinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def isinstances():
result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance]
result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance]

result = isinstance(var[20]) # [too-few-function-args]
result = isinstance() # [too-few-function-args]
result = isinstance(var[20]) # [no-value-for-parameter]
result = isinstance() # [no-value-for-parameter, no-value-for-parameter]

# Combination merged and not merged
result = isinstance(var[12], (int, float)) or isinstance(var[12], list) # [consider-merging-isinstance]
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/c/consider/consider_merging_isinstance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ consider-merging-isinstance:19:13:19:73:isinstances:Consider merging these isins
consider-merging-isinstance:22:13:22:127:isinstances:Consider merging these isinstance calls to isinstance(var[6], (float, int)):UNDEFINED
consider-merging-isinstance:23:13:23:158:isinstances:Consider merging these isinstance calls to isinstance(var[10], (list, str)):UNDEFINED
consider-merging-isinstance:24:13:24:95:isinstances:Consider merging these isinstance calls to isinstance(var[11], (float, int)):UNDEFINED
too-few-function-args:26:13:26:32:isinstances:Too few positional arguments for function call:HIGH
too-few-function-args:27:13:27:25:isinstances:Too few positional arguments for function call:HIGH
no-value-for-parameter:26:13:26:32:isinstances:No value for argument '__class_or_tuple' in function call:HIGH
no-value-for-parameter:27:13:27:25:isinstances:No value for argument '__class_or_tuple' in function call:HIGH
no-value-for-parameter:27:13:27:25:isinstances:No value for argument '_obj' in function call:HIGH
consider-merging-isinstance:30:13:30:75:isinstances:Consider merging these isinstance calls to isinstance(var[12], (float, int, list)):UNDEFINED
3 changes: 0 additions & 3 deletions tests/functional/t/too/too_few_function_args.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/functional/t/too/too_few_function_args.txt

This file was deleted.

0 comments on commit 40f58ea

Please sign in to comment.