summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-12-02 23:39:43 (GMT)
committerGitHub <noreply@github.com>2023-12-02 23:39:43 (GMT)
commita9574c68f04695eecd19866faaf4cdee5965bc70 (patch)
tree6c4738f5b6b8e92c7fe8716418fb8b26a633e703 /Lib/pydoc.py
parent0229d2a9b1d6ce6daa6a773f92e3754e7dc86d50 (diff)
downloadcpython-a9574c68f04695eecd19866faaf4cdee5965bc70.zip
cpython-a9574c68f04695eecd19866faaf4cdee5965bc70.tar.gz
cpython-a9574c68f04695eecd19866faaf4cdee5965bc70.tar.bz2
gh-112139: Add `inspect.Signature.format` and use it in `pydoc` (#112143)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index be41592..83c74a7 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -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: