diff --git a/CHANGES b/CHANGES index bfab61b7d..ad84c4155 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,7 @@ Bugs fixed * #2899: Fix ``hasdoc()`` function in Jinja2 template. It can detect ``genindex``, ``search`` collectly. * #2901: Fix epub result: skip creating links from image tags to original image files. * #2917: inline code is hyphenated on HTML +* #1462: autosummary warns for namedtuple with attribute with trailing underscore Release 1.4.6 (released Aug 20, 2016) ===================================== diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 3635ad07f..a941aa33a 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -67,6 +67,7 @@ from docutils import nodes import sphinx from sphinx import addnodes +from sphinx.util import rst from sphinx.util.compat import Directive from sphinx.pycode import ModuleAnalyzer, PycodeError from sphinx.ext.autodoc import Options @@ -367,7 +368,7 @@ class Autosummary(Directive): for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: - col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig) + col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig)) else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py new file mode 100644 index 000000000..437ba516b --- /dev/null +++ b/sphinx/util/rst.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +""" + sphinx.util.rst + ~~~~~~~~~~~~~~~ + + reST helper functions. + + :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +symbols_re = re.compile('([!-/:-@\[-`{-~])') + + +def escape(text): + return symbols_re.sub(r'\\\1', text) diff --git a/tests/roots/test-autosummary/dummy_module.py b/tests/roots/test-autosummary/dummy_module.py index a64035d69..1f4a47378 100644 --- a/tests/roots/test-autosummary/dummy_module.py +++ b/tests/roots/test-autosummary/dummy_module.py @@ -69,3 +69,7 @@ class C: ''' This is a nested inner class docstring ''' + + +def func(arg_): + """Test function take an argument ended with underscore.""" diff --git a/tests/test_util_rst.py b/tests/test_util_rst.py new file mode 100644 index 000000000..72cd87fe8 --- /dev/null +++ b/tests/test_util_rst.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" + test_util_rst + ~~~~~~~~~~~~~~~ + + Tests sphinx.util.rst functions. + + :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +from sphinx.util.rst import escape + + +def test_escape(): + assert escape(':ref:`id`') == '\:ref\:\`id\`' + assert escape('footnote [#]_') == 'footnote \[\#\]\_'