summaryrefslogtreecommitdiff
path: root/tests/functional/k/kwarg_superseded_by_positional_arg.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/k/kwarg_superseded_by_positional_arg.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/k/kwarg_superseded_by_positional_arg.py')
-rw-r--r--tests/functional/k/kwarg_superseded_by_positional_arg.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/functional/k/kwarg_superseded_by_positional_arg.py b/tests/functional/k/kwarg_superseded_by_positional_arg.py
new file mode 100644
index 000000000..050b2066c
--- /dev/null
+++ b/tests/functional/k/kwarg_superseded_by_positional_arg.py
@@ -0,0 +1,39 @@
+"""
+The `kwarg-superseded-by-positional-arg` warning message is emitted when a function is called with
+a keyword argument which shares a name with a positional-only parameter and
+the function contains a keyword variadic parameter dictionary.
+It may be surprising behaviour when the keyword argument is added to the
+keyword variadic parameter dictionary.
+"""
+
+
+def name1(apple, /, banana="Yellow banana", **kwargs):
+ """
+ Positional-only parameter, positional-or-keyword parameter and `**kwargs`.
+
+ >>> name1("Red apple", apple="Green apple", banana="Green banana")
+ Red apple
+ Green banana
+ {"apple": "Green apple"}
+ """
+
+ print(apple)
+ print(banana)
+ print(kwargs)
+
+
+# +1: [kwarg-superseded-by-positional-arg]
+name1("Red apple", apple="Green apple", banana="Green banana")
+name1("Red apple", banana="Green banana")
+
+
+def name2(apple="Green apple", /, **kwargs):
+ """
+ >>> name2(apple="Red apple")
+ Green apple
+ {'apple': 'Red apple'}
+ """
+ print(apple)
+ print(kwargs)
+
+name2(apple="Red apple") # [kwarg-superseded-by-positional-arg]