mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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:
parent
b502573f7f
commit
78406382c9
8 changed files with 126 additions and 27 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue