From 2db55f6a48962aa7ff4cc3b0ee4b37177f605bdc Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Sat, 15 Apr 2023 03:53:00 +0200 Subject: Fix false negative for no-value-for-parameter: positional-only args and **kwargs (#8575) --- doc/whatsnew/fragments/8559.false_negative | 3 +++ pylint/checkers/typecheck.py | 5 +++++ tests/functional/a/arguments_positional_only.py | 15 +++++++++++++++ tests/functional/a/arguments_positional_only.rc | 2 ++ tests/functional/a/arguments_positional_only.txt | 1 + 5 files changed, 26 insertions(+) create mode 100644 doc/whatsnew/fragments/8559.false_negative create mode 100644 tests/functional/a/arguments_positional_only.py create mode 100644 tests/functional/a/arguments_positional_only.rc create mode 100644 tests/functional/a/arguments_positional_only.txt diff --git a/doc/whatsnew/fragments/8559.false_negative b/doc/whatsnew/fragments/8559.false_negative new file mode 100644 index 000000000..37c415138 --- /dev/null +++ b/doc/whatsnew/fragments/8559.false_negative @@ -0,0 +1,3 @@ +Fix false negative for ``no-value-for-parameter`` when a function, whose signature contains both a positional-only parameter ``name`` and also ``*kwargs``, is called with a keyword-argument for ``name``. + +Closes #8559 diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 6dac7ede5..19bdb39aa 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -1569,6 +1569,11 @@ accessed. Python regular expressions are accepted.", node=node, args=(keyword, callable_name), ) + elif ( + keyword in [arg.name for arg in called.args.posonlyargs] + and called.args.kwarg + ): + pass else: parameters[i] = (parameters[i][0], True) elif keyword in kwparams: diff --git a/tests/functional/a/arguments_positional_only.py b/tests/functional/a/arguments_positional_only.py new file mode 100644 index 000000000..eb03f1803 --- /dev/null +++ b/tests/functional/a/arguments_positional_only.py @@ -0,0 +1,15 @@ +"""Test `no-value-for-parameter` in the context of positional-only parameters""" + +# pylint: disable=missing-docstring, unused-argument + + +def name1(param1, /, **kwargs): ... +def name2(param1, /, param2, **kwargs): ... +def name3(param1=True, /, **kwargs): ... +def name4(param1, **kwargs): ... + +name1(param1=43) # [no-value-for-parameter] +name1(43) +name2(1, param2=False) +name3() +name4(param1=43) diff --git a/tests/functional/a/arguments_positional_only.rc b/tests/functional/a/arguments_positional_only.rc new file mode 100644 index 000000000..85fc502b3 --- /dev/null +++ b/tests/functional/a/arguments_positional_only.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.8 diff --git a/tests/functional/a/arguments_positional_only.txt b/tests/functional/a/arguments_positional_only.txt new file mode 100644 index 000000000..7112e6880 --- /dev/null +++ b/tests/functional/a/arguments_positional_only.txt @@ -0,0 +1 @@ +no-value-for-parameter:11:0:11:16::No value for argument 'param1' in function call:UNDEFINED -- cgit v1.2.1