From ba5093b1670de5e71cbc5eeae58ba6c315c7846d Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Wed, 30 Nov 2022 16:36:21 -0300 Subject: [PATCH 1/4] escape arg underscore --- 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..b337843693 --- /dev/null +++ b/doc/whatsnew/fragments/7827.false_positive @@ -0,0 +1,3 @@ +Fix ``missing-param-doc`` false positive when function parameter has escaped underscore. + +Closes #7827 diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index 46f0a2ac6b..d74513ca2f 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -644,7 +644,7 @@ def match_param_docs(self) -> tuple[set[str], set[str]]: entries = self._parse_section(self.re_param_section) entries.extend(self._parse_section(self.re_keyword_param_section)) for entry in entries: - match = self.re_param_line.match(entry) + match = self.re_param_line.match(entry.replace("\\", "")) if not match: continue 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..5989352439 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 _ is handled correctly. + + Args: + something: the something + raise\\_: the other + + Returns: + something + """ + return something and raise_ From 47d416c7379bd7ba609bbae3c2ee8e6139492f14 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Sun, 4 Dec 2022 09:54:52 -0300 Subject: [PATCH 2/4] update code around match re --- pylint/extensions/_check_docs_utils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index d74513ca2f..2d2d42a469 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -644,16 +644,13 @@ def match_param_docs(self) -> tuple[set[str], set[str]]: entries = self._parse_section(self.re_param_section) entries.extend(self._parse_section(self.re_keyword_param_section)) for entry in entries: - match = self.re_param_line.match(entry.replace("\\", "")) + # Remove escape characters necessary for asterisks and trailing underscores + entry = entry.replace("\\", "") + match = self.re_param_line.match(entry) if not match: continue - param_name = match.group(1) - # Remove escape characters necessary for asterisks - param_name = param_name.replace("\\", "") - - param_type = match.group(2) - param_desc = match.group(3) + param_name, param_type, param_desc = match.groups() if param_type: params_with_type.add(param_name) From 42aba499497d4c4a67f27e45c57ebed9159d01bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sun, 4 Dec 2022 14:23:54 +0100 Subject: [PATCH 3/4] Use regex --- pylint/extensions/_check_docs_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index 2d2d42a469..99d19cc5fa 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)? @@ -645,12 +645,16 @@ def match_param_docs(self) -> tuple[set[str], set[str]]: entries.extend(self._parse_section(self.re_keyword_param_section)) for entry in entries: # Remove escape characters necessary for asterisks and trailing underscores - entry = entry.replace("\\", "") match = self.re_param_line.match(entry) if not match: continue - param_name, param_type, param_desc = match.groups() + param_name = match.group(1) + # Remove escape characters necessary for asterisks + param_name = param_name.replace("\\", "") + + param_type = match.group(2) + param_desc = match.group(3) if param_type: params_with_type.add(param_name) From 6097f34e2cac1f290a8c363b2346b3f580536cfa Mon Sep 17 00:00:00 2001 From: Dani Alcala <112832187+clavedeluna@users.noreply.github.com> Date: Sun, 4 Dec 2022 10:57:20 -0300 Subject: [PATCH 4/4] Apply suggestions from code review 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> --- doc/whatsnew/fragments/7827.false_positive | 2 +- pylint/extensions/_check_docs_utils.py | 1 - .../docparams/parameter/missing_param_doc_required_Google.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/whatsnew/fragments/7827.false_positive b/doc/whatsnew/fragments/7827.false_positive index b337843693..e981fa45f1 100644 --- a/doc/whatsnew/fragments/7827.false_positive +++ b/doc/whatsnew/fragments/7827.false_positive @@ -1,3 +1,3 @@ -Fix ``missing-param-doc`` false positive when function parameter has escaped underscore. +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 99d19cc5fa..811bd67b57 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -644,7 +644,6 @@ def match_param_docs(self) -> tuple[set[str], set[str]]: entries = self._parse_section(self.re_param_section) entries.extend(self._parse_section(self.re_keyword_param_section)) for entry in entries: - # Remove escape characters necessary for asterisks and trailing underscores match = self.re_param_line.match(entry) if not match: continue 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 5989352439..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 @@ -435,7 +435,7 @@ def test_finds_multiple_complex_types_google( ) def test_escape_underscore(something: int, raise_: bool = False) -> bool: - """Tests param with _ is handled correctly. + """Tests param with escaped _ is handled correctly. Args: something: the something