Skip to content

Commit

Permalink
Merge pull request sphinx-doc#6395 from tk0miya/6350_autosummary_is_c…
Browse files Browse the repository at this point in the history
…onfused_by_default_value

Fix sphinx-doc#6350: autosummary is confused by an argument having some kind of default value
  • Loading branch information
tk0miya committed May 26, 2019
2 parents 9f59a04 + dd1b5be commit 224551c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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 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
Expand Down
18 changes: 14 additions & 4 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,20 @@ def mangle_signature(sig, max_chars=30):
# Remove parenthesis
s = re.sub(r"^\((.*)\)$", r"\1", s).strip()

# Strip strings (which can contain things that confuse the code below)
s = re.sub(r"\\\\", "", s)
s = re.sub(r"\\'", "", s)
s = re.sub(r"'[^']*'", "", s)
# Strip literals (which can contain things that confuse the code below)
s = re.sub(r"\\\\", "", s) # escaped backslash (maybe inside string)
s = re.sub(r"\\'", "", s) # escaped single quote
s = re.sub(r'\\"', "", s) # escaped double quote
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]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_ext_autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def test_mangle_signature():
(a, b[, c]) :: (a, b[, c])
(a, b[, cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]) :: (a, b[, ...)
(a, b='c=d, e=f, g=h', c=3) :: (a[, b, c])
(a, b="c=d, e=f, g=h", c=3) :: (a[, b, c])
(a, b='c=d, \\'e=f,\\' g=h', c=3) :: (a[, b, c])
(a, b='c=d, ', e='\\\\' g=h, c=3) :: (a[, b, e, c])
(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)
"""

Expand Down

0 comments on commit 224551c

Please sign in to comment.