gh-101552: Allow pydoc to display signatures in source format (#124669)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra 2024-10-08 22:03:53 -07:00 committed by GitHub
parent b502573f7f
commit 78406382c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 126 additions and 27 deletions

View file

@ -71,6 +71,7 @@ import time
import tokenize
import urllib.parse
import warnings
from annotationlib import Format
from collections import deque
from reprlib import Repr
from traceback import format_exception_only
@ -212,12 +213,12 @@ def splitdoc(doc):
def _getargspec(object):
try:
signature = inspect.signature(object)
signature = inspect.signature(object, annotation_format=Format.STRING)
if 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)
return signature.format(max_width=max_width, quote_annotation_strings=False)
except (ValueError, TypeError):
argspec = getattr(object, '__text_signature__', None)
if argspec: