From 19c0534802980f24a6170f8d880cf99ae08e04fb Mon Sep 17 00:00:00 2001 From: Dani Alcala <112832187+clavedeluna@users.noreply.github.com> Date: Sun, 4 Dec 2022 12:15:14 -0300 Subject: [PATCH] Fix ``missing-param-doc`` for escaped underscores (#7878) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> (cherry picked from commit 1913635db913e97f8866bb7e6e3dc1ca993f5a24) --- doc/whatsnew/fragments/7827.false_positive | 3 +++ pylint/extensions/_check_docs_utils.py | 2 +- .../parameter/missing_param_doc_required_Google.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 doc/whatsnew/fragments/7827.false_positive diff --git a/doc/whatsnew/fragments/7827.false_positive b/doc/whatsnew/fragments/7827.false_positive new file mode 100644 index 0000000000..e981fa45f1 --- /dev/null +++ b/doc/whatsnew/fragments/7827.false_positive @@ -0,0 +1,3 @@ +Fix ``missing-param-doc`` false positive when function parameter has an escaped underscore. + +Closes #7827 diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index d8f797b6c5..69b5482215 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -471,7 +471,7 @@ class GoogleDocstring(Docstring): re_param_line = re.compile( rf""" - \s* ((?:\\?\*{{0,2}})?\w+) # identifier potentially with asterisks + \s* ((?:\\?\*{{0,2}})?[\w\\]+) # identifier potentially with asterisks or escaped `\` \s* ( [(] {re_multiple_type} (?:,\s+optional)? diff --git a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.py b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.py index 18fbaf0490..92646a87f4 100644 --- a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.py +++ b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.py @@ -433,3 +433,15 @@ def test_finds_multiple_complex_types_google( named_arg_nine, named_arg_ten, ) + +def test_escape_underscore(something: int, raise_: bool = False) -> bool: + """Tests param with escaped _ is handled correctly. + + Args: + something: the something + raise\\_: the other + + Returns: + something + """ + return something and raise_