Skip to content

Commit 80e43a9

Browse files
typecheck: simplify variadic positional detection (#5417)
The isinstance checks were not necessary here and caused several false positives where a function with variadic positional argument was called, like for example when the call is used as a function argument, in a if, while or with statement. Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 1f1c7b9 commit 80e43a9

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ contributors:
581581

582582
* Harshil (harshil21): contributor
583583

584+
* Jérome Perrin (perrinjerome): contributor
585+
584586
* Felix von Drigalski (felixvd): contributor
585587

586588
* Philipp Albrecht (pylbrecht): contributor

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Release date: TBA
3232
* Some files in ``pylint.testutils`` were deprecated. In the future imports should be done from the
3333
``pylint.testutils.functional`` namespace directly.
3434

35+
* Fixed false positives for ``no-value-for-parameter`` with variadic
36+
positional arguments.
37+
38+
Closes #5416
39+
3540
* ``safe_infer`` no longer makes an inference when given two function
3641
definitions with differing numbers of arguments.
3742

pylint/checkers/typecheck.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,17 +630,7 @@ def _no_context_variadic_keywords(node, scope):
630630

631631

632632
def _no_context_variadic_positional(node, scope):
633-
variadics = ()
634-
if isinstance(scope, nodes.Lambda) and not isinstance(scope, nodes.FunctionDef):
635-
variadics = node.starargs + node.kwargs
636-
else:
637-
statement = node.statement()
638-
if isinstance(
639-
statement, (nodes.Expr, nodes.Return, nodes.Assign)
640-
) and isinstance(statement.value, nodes.Call):
641-
call = statement.value
642-
variadics = call.starargs + call.kwargs
643-
633+
variadics = node.starargs + node.kwargs
644634
return _no_context_variadic(node, scope.args.vararg, nodes.Starred, variadics)
645635

646636

tests/functional/r/regression/regression_no_value_for_parameter.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@ def varargs_good(*parts):
2828

2929

3030
def varargs_no_expr(*parts):
31-
"""False positive below this line"""
31+
"""False positives below this line"""
3232
ret = os.path.join(*parts)
33-
return ret
33+
if ret:
34+
return ret
35+
print(os.path.join(*parts))
36+
if os.path.join(*parts):
37+
print()
38+
elif os.path.join(*parts):
39+
print()
40+
while os.path.join(*parts):
41+
print()
42+
with os.path.join(*parts): # pylint:disable=not-context-manager
43+
print()
44+
return os.path.join(*parts) + os.path.join(*parts) - os.path.join(*parts)
3445

3546

3647
def kwargs_good(**kwargs):
@@ -39,4 +50,15 @@ def kwargs_good(**kwargs):
3950

4051
def kwargs_no_expr(**kwargs):
4152
ret = func(**kwargs)
42-
return ret
53+
if ret:
54+
return ret
55+
print(func(**kwargs))
56+
if func(**kwargs):
57+
print()
58+
elif func(**kwargs):
59+
print()
60+
while func(**kwargs):
61+
print()
62+
with func(**kwargs): # pylint:disable=not-context-manager
63+
print()
64+
return func(**kwargs) + func(**kwargs) - func(**kwargs)

0 commit comments

Comments
 (0)