Fix #6350: autosummary is confused by an argument having namedtuple as a default value

This commit is contained in:
Takeshi KOMIYA 2019-05-11 18:07:50 +09:00
parent 5d640f3c10
commit dd1b5beb74
3 changed files with 10 additions and 2 deletions

View File

@ -118,8 +118,7 @@ Bugs fixed
referenced
* #6165: autodoc: ``tab_width`` setting of docutils has been ignored
* #6311: autosummary: autosummary table gets confused by complex type hints
* #6350: autosummary: confused by an argument having default string value
containing a single quote
* #6350: autosummary: confused by an argument having some kind of default value
* Generated Makefiles lack a final EOL (refs: #6232)
* #6375: extlinks: Cannot escape angle brackets in link caption
* #6378: linkcheck: Send commonly used User-Agent

View File

@ -451,6 +451,14 @@ def mangle_signature(sig, max_chars=30):
s = re.sub(r"'[^']*'", "", s) # string literal (w/ single quote)
s = re.sub(r'"[^"]*"', "", s) # string literal (w/ double quote)
# Strip complex objects (maybe default value of arguments)
while re.search(r'\([^)]*\)', s): # contents of parenthesis (ex. NamedTuple(attr=...))
s = re.sub(r'\([^)]*\)', '', s)
while re.search(r'<[^>]*>', s): # contents of angle brackets (ex. <object>)
s = re.sub(r'<[^>]*>', '', s)
while re.search(r'{[^}]*}', s): # contents of curly brackets (ex. dict)
s = re.sub(r'{[^}]*}', '', s)
# Parse the signature to arguments + options
args = [] # type: List[str]
opts = [] # type: List[str]

View File

@ -53,6 +53,7 @@ def test_mangle_signature():
(a, b={'c=d, ': 3, '\\\\': 3}) :: (a[, b])
(a=1, b=2, c=3) :: ([a, b, c])
(a=1, b=<SomeClass: a, b, c>, c=3) :: ([a, b, c])
(a=1, b=T(a=1, b=2), c=3) :: ([a, b, c])
(a: int, b: int) -> str :: (a, b)
"""