Skip to content

Commit 40f58ea

Browse files
too-few-function-args redundant with no-value-for-parameter (#9882)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent a32250c commit 40f58ea

File tree

14 files changed

+22
-34
lines changed

14 files changed

+22
-34
lines changed

doc/data/messages/t/too-few-function-args/bad.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/data/messages/t/too-few-function-args/details.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

doc/data/messages/t/too-few-function-args/good.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/user_guide/checkers/features.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,6 @@ Typecheck checker Messages
12411241
:invalid-slice-step (E1144): *Slice step cannot be 0*
12421242
Used when a slice step is 0 and the object doesn't implement a custom
12431243
__getitem__ method.
1244-
:too-few-function-args (E1145): *Too few positional arguments for %s call*
1245-
Used when a function or method call has fewer arguments than expected.
12461244
:too-many-function-args (E1121): *Too many positional arguments for %s call*
12471245
Used when a function call passes too many positional arguments.
12481246
:unexpected-keyword-arg (E1123): *Unexpected keyword argument %r in %s call*

doc/user_guide/messages/messages_overview.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ All messages in the error category:
155155
error/star-needs-assignment-target
156156
error/syntax-error
157157
error/too-few-format-args
158-
error/too-few-function-args
159158
error/too-many-format-args
160159
error/too-many-function-args
161160
error/too-many-star-expressions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Fix a false negative when `isinstance` has too many arguments.
2-
Change now emits a `too-many-function-args` output with behavior similar to other
3-
`too-many-function-args` calls.
1+
Fix false negatives when `isinstance` does not have exactly two arguments.
2+
pylint now emits a `too-many-function-args` or `no-value-for-parameter`
3+
appropriately for `isinstance` calls.
44

55
Closes #9847

doc/whatsnew/fragments/9847.new_check

Lines changed: 0 additions & 5 deletions
This file was deleted.

pylint/checkers/typecheck.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ def _missing_member_hint(
377377
"Used when a slice step is 0 and the object doesn't implement "
378378
"a custom __getitem__ method.",
379379
),
380-
"E1145": (
381-
"Too few positional arguments for %s call",
382-
"too-few-function-args",
383-
"Used when a function or method call has fewer arguments than expected.",
384-
),
385380
"W1113": (
386381
"Keyword argument before variable positional arguments list "
387382
"in the definition of %s function",
@@ -1434,12 +1429,17 @@ def _check_isinstance_args(self, node: nodes.Call, callable_name: str) -> None:
14341429
confidence=HIGH,
14351430
)
14361431
elif len(node.args) < 2:
1437-
self.add_message(
1438-
"too-few-function-args",
1439-
node=node,
1440-
args=(callable_name,),
1441-
confidence=HIGH,
1442-
)
1432+
# NOTE: Hard-coding the parameters for `isinstance` is fragile,
1433+
# but as noted elsewhere, built-in functions do not provide
1434+
# argument info, making this necessary for now.
1435+
parameters = ("'_obj'", "'__class_or_tuple'")
1436+
for parameter in parameters[len(node.args) :]:
1437+
self.add_message(
1438+
"no-value-for-parameter",
1439+
node=node,
1440+
args=(parameter, callable_name),
1441+
confidence=HIGH,
1442+
)
14431443
return
14441444

14451445
second_arg = node.args[1]

tests/functional/a/arguments.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,5 @@ def func(string):
331331

332332
func(42)
333333
a = func(42)
334+
335+
isinstance(1) # [no-value-for-parameter]

tests/functional/a/arguments.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ no-value-for-parameter:217:0:217:30::No value for argument 'second' in function
3939
unexpected-keyword-arg:218:0:218:43::Unexpected keyword argument 'fourth' in function call:UNDEFINED
4040
redundant-keyword-arg:308:0:308:79::Argument 'banana' passed by position and keyword in function call:UNDEFINED
4141
no-value-for-parameter:318:0:318:16::No value for argument 'param1' in function call:UNDEFINED
42+
no-value-for-parameter:335:0:335:13::No value for argument '__class_or_tuple' in function call:HIGH

0 commit comments

Comments
 (0)