mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-112139: Add inspect.Signature.format
and use it in pydoc
(#112143)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
0229d2a9b1
commit
a9574c68f0
6 changed files with 205 additions and 11 deletions
|
@ -201,7 +201,10 @@ def _getargspec(object):
|
|||
try:
|
||||
signature = inspect.signature(object)
|
||||
if signature:
|
||||
return str(signature)
|
||||
name = getattr(object, '__name__', '')
|
||||
# <lambda> function are always single-line and should not be formatted
|
||||
max_width = (80 - len(name)) if name != '<lambda>' else None
|
||||
return signature.format(max_width=max_width)
|
||||
except (ValueError, TypeError):
|
||||
argspec = getattr(object, '__text_signature__', None)
|
||||
if argspec:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue