Skip to content

Commit c1bd7aa

Browse files
authored
Merge pull request #23 from Chilipp/sphinx-2.4.0-patch
Compatibility fixes for sphinx 2.4.0
2 parents 3f73cc7 + a9e899c commit c1bd7aa

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

autodocsumm/__init__.py

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@
2424
from docutils import nodes
2525
from docutils.statemachine import ViewList
2626

27+
signature = Signature = None
28+
2729
if sphinx.__version__ >= '1.7':
28-
from sphinx.ext.autodoc import Signature, get_documenters
30+
from sphinx.ext.autodoc import get_documenters
2931
from sphinx.ext.autodoc.directive import (
3032
AutodocDirective, AUTODOC_DEFAULT_OPTIONS, DocumenterBridge,
3133
process_documenter_options)
34+
try:
35+
from sphinx.util.inspect import signature, stringify_signature
36+
except ImportError:
37+
from sphinx.ext.autodoc import Signature
38+
3239
else:
3340
from sphinx.ext.autodoc import (
3441
getargspec, formatargspec, AutoDirective as AutodocDirective,
@@ -67,6 +74,35 @@
6774
'ignore-module-all'}
6875

6976

77+
if signature is not None: # sphinx >= 2.4.0
78+
def process_signature(obj):
79+
sig = signature(obj)
80+
return stringify_signature(sig)
81+
elif Signature is not None: # sphinx >= 1.7
82+
def process_signature(obj):
83+
try:
84+
args = Signature(obj).format_args()
85+
except TypeError:
86+
return None
87+
else:
88+
args = args.replace('\\', '\\\\')
89+
return args
90+
else:
91+
def process_signature(obj):
92+
try:
93+
argspec = getargspec(obj)
94+
except TypeError:
95+
# still not possible: happens e.g. for old-style classes
96+
# with __call__ in C
97+
return None
98+
if argspec[0] and argspec[0][0] in ('cls', 'self'):
99+
del argspec[0][0]
100+
if sphinx_version < [1, 4]:
101+
return formatargspec(*argspec)
102+
else:
103+
return formatargspec(obj, *argspec)
104+
105+
70106
class AutosummaryDocumenter(object):
71107
"""Abstract class for for extending Documenter methods
72108
@@ -276,26 +312,9 @@ def format_args(self):
276312
if callmeth is None:
277313
return None
278314
if sphinx_version < [1, 7]:
279-
try:
280-
argspec = getargspec(callmeth)
281-
except TypeError:
282-
# still not possible: happens e.g. for old-style classes
283-
# with __call__ in C
284-
return None
285-
if argspec[0] and argspec[0][0] in ('cls', 'self'):
286-
del argspec[0][0]
287-
if sphinx_version < [1, 4]:
288-
return formatargspec(*argspec)
289-
else:
290-
return formatargspec(callmeth, *argspec)
315+
pass
291316
else:
292-
try:
293-
args = Signature(callmeth).format_args()
294-
except TypeError:
295-
return None
296-
else:
297-
args = args.replace('\\', '\\\\')
298-
return args
317+
return process_signature(callmeth)
299318

300319
def get_doc(self, encoding=None, ignore=1):
301320
"""Reimplemented to include data from the call method"""
@@ -339,27 +358,7 @@ def format_args(self):
339358
callmeth = self.get_attr(self.object, '__call__', None)
340359
if callmeth is None:
341360
return None
342-
if sphinx_version < [1, 7]:
343-
try:
344-
argspec = getargspec(callmeth)
345-
except TypeError:
346-
# still not possible: happens e.g. for old-style classes
347-
# with __call__ in C
348-
return None
349-
if argspec[0] and argspec[0][0] in ('cls', 'self'):
350-
del argspec[0][0]
351-
if sphinx_version < [1, 4]:
352-
return formatargspec(*argspec)
353-
else:
354-
return formatargspec(callmeth, *argspec)
355-
else:
356-
try:
357-
args = Signature(callmeth).format_args()
358-
except TypeError:
359-
return None
360-
else:
361-
args = args.replace('\\', '\\\\')
362-
return args
361+
return process_signature(callmeth)
363362

364363
def get_doc(self, encoding=None, ignore=1):
365364
"""Reimplemented to include data from the call method"""

0 commit comments

Comments
 (0)