From c4dfc7402ed022ecdb1cd85b5f69ef1e583efd29 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 9 Jun 2019 00:23:18 +0900 Subject: [PATCH] Fix #6436: napoleon: "Unknown target name" error --- CHANGES | 2 ++ sphinx/ext/napoleon/docstring.py | 3 +++ tests/test_ext_napoleon_docstring.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 7043d835d..a869afb82 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,8 @@ Bugs fixed immediately preceding section title by pagebreak * #6448: autodoc: crashed when autodocumenting classes with ``__slots__ = None`` * #6452: autosummary: crashed when generating document of properties +* #6436: napoleon: "Unknown target name" error if variable name ends with + underscore Testing -------- diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 0fea99fb8..f57e2481c 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -328,6 +328,9 @@ class GoogleDocstring: def _escape_args_and_kwargs(self, name): # type: (str) -> str + if name.endswith('_'): + name = name[:-1] + r'\_' + if name[:2] == '**': return r'\*\*' + name[2:] elif name[:1] == '*': diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index a333dc47b..f1714bd62 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1351,8 +1351,8 @@ arg_ : type """ expected = """ -:ivar arg_: some description -:vartype arg_: type +:ivar arg\\_: some description +:vartype arg\\_: type """ config = Config(napoleon_use_ivar=True)