mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
* In autodoc, fix display of parameter defaults containing backslashes. Closes #1502
This commit is contained in:
parent
f781f55b28
commit
b3aa4aa81b
1
CHANGES
1
CHANGES
@ -17,6 +17,7 @@ Bugs fixed
|
||||
* #1441: autosummary can't handle nested classes correctly.
|
||||
* #1499: With non-callable `setup` in a conf.py, now sphinx-build emits
|
||||
user-friendly error message.
|
||||
* #1502: In autodoc, fix display of parameter defaults containing backslashes.
|
||||
|
||||
Release 1.2.2 (released Mar 2, 2014)
|
||||
====================================
|
||||
|
@ -1225,7 +1225,10 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter):
|
||||
argspec = getargspec(self.object)
|
||||
if argspec[0] and argspec[0][0] in ('cls', 'self'):
|
||||
del argspec[0][0]
|
||||
return inspect.formatargspec(*argspec)
|
||||
args = inspect.formatargspec(*argspec)
|
||||
# escape backslashes for reST
|
||||
args = args.replace('\\', '\\\\')
|
||||
return args
|
||||
|
||||
def document_members(self, all_members=False):
|
||||
pass
|
||||
|
@ -163,10 +163,13 @@ def test_format_signature():
|
||||
# test for functions
|
||||
def f(a, b, c=1, **d):
|
||||
pass
|
||||
def g(a='\n'):
|
||||
pass
|
||||
assert formatsig('function', 'f', f, None, None) == '(a, b, c=1, **d)'
|
||||
assert formatsig('function', 'f', f, 'a, b, c, d', None) == '(a, b, c, d)'
|
||||
assert formatsig('function', 'f', f, None, 'None') == \
|
||||
'(a, b, c=1, **d) -> None'
|
||||
assert formatsig('function', 'g', g, None, None) == r"(a='\\n')"
|
||||
|
||||
# test for classes
|
||||
class D:
|
||||
@ -206,9 +209,12 @@ def test_format_signature():
|
||||
pass
|
||||
def foo2(b, *c):
|
||||
pass
|
||||
def foo3(self, d='\n'):
|
||||
pass
|
||||
assert formatsig('method', 'H.foo', H.foo1, None, None) == '(b, *c)'
|
||||
assert formatsig('method', 'H.foo', H.foo1, 'a', None) == '(a)'
|
||||
assert formatsig('method', 'H.foo', H.foo2, None, None) == '(b, *c)'
|
||||
assert formatsig('method', 'H.foo', H.foo3, None, None) == r"(d='\\n')"
|
||||
|
||||
# test exception handling (exception is caught and args is '')
|
||||
assert formatsig('function', 'int', int, None, None) == ''
|
||||
|
Loading…
Reference in New Issue
Block a user