diff options
author | Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> | 2023-05-16 10:34:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 10:34:47 +0200 |
commit | d392ea5d8a11049a275207cf18e488bf19a57c69 (patch) | |
tree | af336aaa260297d971ed5fbf16acbb32c9dde8c2 /doc | |
parent | 0a6c21bfab8237431c9f5198068451b243e91448 (diff) | |
download | pylint-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 'doc')
-rw-r--r-- | doc/data/messages/k/kwarg-superseded-by-positional-arg/bad.py | 5 | ||||
-rw-r--r-- | doc/data/messages/k/kwarg-superseded-by-positional-arg/good.py | 5 | ||||
-rw-r--r-- | doc/whatsnew/fragments/8558.feature | 3 |
3 files changed, 13 insertions, 0 deletions
diff --git a/doc/data/messages/k/kwarg-superseded-by-positional-arg/bad.py b/doc/data/messages/k/kwarg-superseded-by-positional-arg/bad.py new file mode 100644 index 000000000..87f7d8ccd --- /dev/null +++ b/doc/data/messages/k/kwarg-superseded-by-positional-arg/bad.py @@ -0,0 +1,5 @@ +def print_name(name="Sarah", /, **kwds): + print(name) + + +print_name(name="Jacob") # [kwarg-superseded-by-positional-arg] diff --git a/doc/data/messages/k/kwarg-superseded-by-positional-arg/good.py b/doc/data/messages/k/kwarg-superseded-by-positional-arg/good.py new file mode 100644 index 000000000..86dbfba07 --- /dev/null +++ b/doc/data/messages/k/kwarg-superseded-by-positional-arg/good.py @@ -0,0 +1,5 @@ +def print_name(name="Sarah", /, **kwds): + print(name) + + +print_name("Jacob") diff --git a/doc/whatsnew/fragments/8558.feature b/doc/whatsnew/fragments/8558.feature new file mode 100644 index 000000000..b5a8342f3 --- /dev/null +++ b/doc/whatsnew/fragments/8558.feature @@ -0,0 +1,3 @@ +Add a new checker ``kwarg-superseded-by-positional-arg`` to warn 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. + +Closes #8558 |