summaryrefslogtreecommitdiff
path: root/tests/functional/a/arguments.py
diff options
context:
space:
mode:
authorMark Byrne <31762852+mbyrnepr2@users.noreply.github.com>2023-05-16 10:34:47 +0200
committerGitHub <noreply@github.com>2023-05-16 10:34:47 +0200
commitd392ea5d8a11049a275207cf18e488bf19a57c69 (patch)
treeaf336aaa260297d971ed5fbf16acbb32c9dde8c2 /tests/functional/a/arguments.py
parent0a6c21bfab8237431c9f5198068451b243e91448 (diff)
downloadpylint-git-d392ea5d8a11049a275207cf18e488bf19a57c69.tar.gz
Add new checker `kwarg-superseded-by-positional-arg` and fix a false positive (#8644)
* Fix a false positive for ``redundant-keyword-arg`` when a function, with a keyword-only-parameter and ``**kwargs``, is called with a positional argument and a keyword argument where the keyword argument has the same name as the positional-only-parameter. * Add new checker ``kwarg-superseded-by-positional-arg`` which emits a warning message for the above scenario. Closes #8558 Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/functional/a/arguments.py')
-rw-r--r--tests/functional/a/arguments.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/functional/a/arguments.py b/tests/functional/a/arguments.py
index 29fdbd5ba..81a9bb73d 100644
--- a/tests/functional/a/arguments.py
+++ b/tests/functional/a/arguments.py
@@ -1,6 +1,6 @@
# pylint: disable=too-few-public-methods, missing-docstring,import-error,wrong-import-position
# pylint: disable=wrong-import-order, unnecessary-lambda, consider-using-f-string
-# pylint: disable=unnecessary-lambda-assignment, no-self-argument, unused-argument
+# pylint: disable=unnecessary-lambda-assignment, no-self-argument, unused-argument, kwarg-superseded-by-positional-arg
def decorator(fun):
"""Decorator"""
@@ -278,3 +278,45 @@ class FruitPicker:
picker = FruitPicker()
picker.pick_apple()
picker.pick_pear()
+
+
+def name1(apple, /, **kwargs):
+ """
+ Positional-only parameter with `**kwargs`.
+ Calling this function with the `apple` keyword should not emit
+ `redundant-keyword-arg` since it is added to `**kwargs`.
+
+ >>> name1("Red apple", apple="Green apple")
+ "Red apple"
+ {"apple": "Green apple"}
+ """
+ print(apple)
+ print(kwargs)
+
+
+name1("Red apple", apple="Green apple")
+
+
+def name2(apple, /, banana, **kwargs):
+ """
+ Positional-only parameter with positional-or-keyword parameter and `**kwargs`.
+ """
+
+
+# `banana` is redundant
+# +1:[redundant-keyword-arg]
+name2("Red apple", "Yellow banana", apple="Green apple", banana="Green banana")
+
+
+# Test `no-value-for-parameter` in the context of positional-only parameters
+
+def name3(param1, /, **kwargs): ...
+def name4(param1, /, param2, **kwargs): ...
+def name5(param1=True, /, **kwargs): ...
+def name6(param1, **kwargs): ...
+
+name3(param1=43) # [no-value-for-parameter]
+name3(43)
+name4(1, param2=False)
+name5()
+name6(param1=43)