@@ -197,6 +197,29 @@ def splitdoc(doc):
197
197
return lines [0 ], '\n ' .join (lines [2 :])
198
198
return '' , '\n ' .join (lines )
199
199
200
+ def _getargspec (object ):
201
+ try :
202
+ signature = inspect .signature (object )
203
+ if signature :
204
+ return str (signature )
205
+ except (ValueError , TypeError ):
206
+ argspec = getattr (object , '__text_signature__' , None )
207
+ if argspec :
208
+ if argspec == '($module)' :
209
+ argspec = '()'
210
+ elif argspec [:10 ] == '($module, ' :
211
+ argspec = '(' + argspec [10 :]
212
+ elif argspec == '($self)' and hasattr (object , '__self__' ):
213
+ argspec = '()'
214
+ elif argspec [:8 ] == '($self, ' and hasattr (object , '__self__' ):
215
+ argspec = '(' + argspec [8 :]
216
+ elif argspec [:2 ] == '($' :
217
+ argspec = '(' + argspec [2 :]
218
+ if argspec [:4 ] == '(/, ' :
219
+ argspec = '(' + argspec [4 :]
220
+ return argspec
221
+ return None
222
+
200
223
def classname (object , modname ):
201
224
"""Get a class name and qualify it with a module name if necessary."""
202
225
name = object .__name__
@@ -1003,14 +1026,9 @@ def spilldata(msg, attrs, predicate):
1003
1026
title = title + '(%s)' % ', ' .join (parents )
1004
1027
1005
1028
decl = ''
1006
- try :
1007
- signature = inspect .signature (object )
1008
- except (ValueError , TypeError ):
1009
- signature = None
1010
- if signature :
1011
- argspec = str (signature )
1012
- if argspec and argspec != '()' :
1013
- decl = name + self .escape (argspec ) + '\n \n '
1029
+ argspec = _getargspec (object )
1030
+ if argspec and argspec != '()' :
1031
+ decl = name + self .escape (argspec ) + '\n \n '
1014
1032
1015
1033
doc = getdoc (object )
1016
1034
if decl :
@@ -1063,18 +1081,13 @@ def docroutine(self, object, name=None, mod=None,
1063
1081
anchor , name , reallink )
1064
1082
argspec = None
1065
1083
if inspect .isroutine (object ):
1066
- try :
1067
- signature = inspect .signature (object )
1068
- except (ValueError , TypeError ):
1069
- signature = None
1070
- if signature :
1071
- argspec = str (signature )
1072
- if realname == '<lambda>' :
1073
- title = '<strong>%s</strong> <em>lambda</em> ' % name
1074
- # XXX lambda's won't usually have func_annotations['return']
1075
- # since the syntax doesn't support but it is possible.
1076
- # So removing parentheses isn't truly safe.
1077
- argspec = argspec [1 :- 1 ] # remove parentheses
1084
+ argspec = _getargspec (object )
1085
+ if argspec and realname == '<lambda>' :
1086
+ title = '<strong>%s</strong> <em>lambda</em> ' % name
1087
+ # XXX lambda's won't usually have func_annotations['return']
1088
+ # since the syntax doesn't support but it is possible.
1089
+ # So removing parentheses isn't truly safe.
1090
+ argspec = argspec [1 :- 1 ] # remove parentheses
1078
1091
if not argspec :
1079
1092
argspec = '(...)'
1080
1093
@@ -1321,14 +1334,9 @@ def makename(c, m=object.__module__):
1321
1334
contents = []
1322
1335
push = contents .append
1323
1336
1324
- try :
1325
- signature = inspect .signature (object )
1326
- except (ValueError , TypeError ):
1327
- signature = None
1328
- if signature :
1329
- argspec = str (signature )
1330
- if argspec and argspec != '()' :
1331
- push (name + argspec + '\n ' )
1337
+ argspec = _getargspec (object )
1338
+ if argspec and argspec != '()' :
1339
+ push (name + argspec + '\n ' )
1332
1340
1333
1341
doc = getdoc (object )
1334
1342
if doc :
@@ -1492,18 +1500,13 @@ def docroutine(self, object, name=None, mod=None, cl=None):
1492
1500
argspec = None
1493
1501
1494
1502
if inspect .isroutine (object ):
1495
- try :
1496
- signature = inspect .signature (object )
1497
- except (ValueError , TypeError ):
1498
- signature = None
1499
- if signature :
1500
- argspec = str (signature )
1501
- if realname == '<lambda>' :
1502
- title = self .bold (name ) + ' lambda '
1503
- # XXX lambda's won't usually have func_annotations['return']
1504
- # since the syntax doesn't support but it is possible.
1505
- # So removing parentheses isn't truly safe.
1506
- argspec = argspec [1 :- 1 ] # remove parentheses
1503
+ argspec = _getargspec (object )
1504
+ if argspec and realname == '<lambda>' :
1505
+ title = self .bold (name ) + ' lambda '
1506
+ # XXX lambda's won't usually have func_annotations['return']
1507
+ # since the syntax doesn't support but it is possible.
1508
+ # So removing parentheses isn't truly safe.
1509
+ argspec = argspec [1 :- 1 ] # remove parentheses
1507
1510
if not argspec :
1508
1511
argspec = '(...)'
1509
1512
decl = asyncqualifier + title + argspec + note
0 commit comments