diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-04-15 10:38:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-15 10:38:55 +0200 |
commit | ec96bdc206350e378137da27c2f4cd103a94dc63 (patch) | |
tree | 5c1f8545993ec86533c6360e94ac38a2b244a13b /pylint | |
parent | 16fe498b68c170b317eaea94bf85efd568a1dd0a (diff) | |
download | pylint-git-ec96bdc206350e378137da27c2f4cd103a94dc63.tar.gz |
Fix false positive for ``keyword-arg-before-vararg`` (#8571) (#8578)
* Fix false positive for ``keyword-arg-before-vararg`` when a positional-only parameter with a default value precedes ``*args``.
Closes #8570
(cherry picked from commit 56fa5dce747a46f1dcba6eca003bb22fcc347247)
Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/typecheck.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 0c8c44a15..1a628f231 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -1001,8 +1001,14 @@ accessed. Python regular expressions are accepted.", @only_required_for_messages("keyword-arg-before-vararg") def visit_functiondef(self, node: nodes.FunctionDef) -> None: - # check for keyword arg before varargs + # check for keyword arg before varargs. + if node.args.vararg and node.args.defaults: + # When `positional-only` parameters are present then only + # `positional-or-keyword` parameters are checked. I.e: + # >>> def name(pos_only_params, /, pos_or_keyword_params, *args): ... + if node.args.posonlyargs and not node.args.args: + return self.add_message("keyword-arg-before-vararg", node=node, args=(node.name)) visit_asyncfunctiondef = visit_functiondef |