summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2014-07-12 20:50:15 +0900
committershimizukawa <shimizukawa@gmail.com>2014-07-12 20:50:15 +0900
commit02357d54bcd6a3e1f60d88474248fcdc29ba0459 (patch)
tree34f516f1e74272fd2cce7cee007d1bb13bc26288
parent9f4116685768a8b9bdd3b6fd7009affe7d471ac0 (diff)
downloadsphinx-02357d54bcd6a3e1f60d88474248fcdc29ba0459.tar.gz
* Fix: py:function directive generate incorrectly signature when specifying a default parameter with an empty list `[]`. Closes #1503
-rw-r--r--CHANGES2
-rw-r--r--sphinx/domains/python.py2
-rw-r--r--tests/test_py_domain.py44
3 files changed, 47 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index b75bf852..86e30df3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,8 @@ Bugs fixed
* #1226: autodoc, autosummary: importing setup.py by automodule will invoke
setup process and execute `sys.exit()`. Now sphinx avoids SystemExit
exception and emits warnings without unexpected termination.
+* #1503: py:function directive generate incorrectly signature when specifying
+ a default parameter with an empty list `[]`. Thanks to Geert Jansen.
Release 1.2.2 (released Mar 2, 2014)
====================================
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index 8943198f..792cffd8 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -54,7 +54,7 @@ def _pseudo_parse_arglist(signode, arglist):
while argument.startswith(']'):
stack.pop()
argument = argument[1:].strip()
- while argument.endswith(']'):
+ while argument.endswith(']') and not argument.endswith('[]'):
ends_close += 1
argument = argument[:-1].strip()
while argument.endswith('['):
diff --git a/tests/test_py_domain.py b/tests/test_py_domain.py
new file mode 100644
index 00000000..68634d83
--- /dev/null
+++ b/tests/test_py_domain.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+"""
+ test_py_domain
+ ~~~~~~~~~~~~~~
+
+ Tests the Python Domain
+
+ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from sphinx import addnodes
+from sphinx.domains.python import py_sig_re, _pseudo_parse_arglist
+
+
+def parse(sig):
+ m = py_sig_re.match(sig)
+ if m is None:
+ raise ValueError
+ name_prefix, name, arglist, retann = m.groups()
+ signode = addnodes.desc_signature(sig, '')
+ _pseudo_parse_arglist(signode, arglist)
+ return signode.astext()
+
+
+def test_function_signatures():
+
+ rv = parse('func(a=1) -> int object')
+ assert unicode(rv) == u'a=1'
+
+ rv = parse('func(a=1, [b=None])')
+ assert unicode(rv) == u'a=1, [b=None]'
+
+ rv = parse('func(a=1[, b=None])')
+ assert unicode(rv) == u'a=1, [b=None]'
+
+ rv = parse("compile(source : string, filename, symbol='file')")
+ assert unicode(rv) == u"source : string, filename, symbol='file'"
+
+ rv = parse('func(a=[], [b=None])')
+ assert unicode(rv) == u'a=[], [b=None]'
+
+ rv = parse('func(a=[][, b=None])')
+ assert unicode(rv) == u'a=[], [b=None]'