diff options
| author | Pauli Virtanen <pav@iki.fi> | 2011-06-29 21:26:43 +0200 |
|---|---|---|
| committer | Pauli Virtanen <pav@iki.fi> | 2011-06-29 21:26:43 +0200 |
| commit | d4fb02ff7bf30edef49b879f976565b326cee480 (patch) | |
| tree | fdaa680a1dd8961e142adb5da1d736bbe8c8936b /sphinx/ext | |
| parent | 430f79249a07e378c30e4ee64ac93fab5815aaed (diff) | |
| download | sphinx-d4fb02ff7bf30edef49b879f976565b326cee480.tar.gz | |
autosummary: improve robustness of the signature compactification
Diffstat (limited to 'sphinx/ext')
| -rw-r--r-- | sphinx/ext/autosummary/__init__.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index aad8b9f6..82637583 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -322,13 +322,29 @@ class Autosummary(Directive): def mangle_signature(sig, max_chars=30): """Reformat a function signature to a more compact form.""" - sig = re.sub(r"^\((.*)\)$", r"\1", sig) + ", " - r = re.compile(r"(?P<name>[a-zA-Z0-9_*]+)(?P<default>=.*?)?, ") - items = r.findall(sig) + s = re.sub(r"^\((.*)\)$", r"\1", sig).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) + + # Parse the signature to arguments + options + args = [] + opts = [] + + opt_re = re.compile(r"^(.*, |)([a-zA-Z0-9_*]+)=") + while s: + m = opt_re.search(s) + if not m: + # The rest are arguments + args = s.split(', ') + break - args = [name for name, default in items if not default] - opts = [name for name, default in items if default] + opts.insert(0, m.group(2)) + s = m.group(1)[:-2] + # Produce a more compact signature sig = limited_join(", ", args, max_chars=max_chars-2) if opts: if not sig: |
