mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-45438: format of inspect.Signature with generic builtins (#29212)
Use types.GenericAlias in inspect.formatannotation to correctly add type arguments of builtin types to the string representation of Signatures. Co-authored-by: Martin Rückl <martin.rueckl@codecentric.de>
This commit is contained in:
parent
10bbd41ba8
commit
d02ffd1b5c
3 changed files with 14 additions and 0 deletions
|
|
@ -1325,6 +1325,8 @@ def getargvalues(frame):
|
|||
def formatannotation(annotation, base_module=None):
|
||||
if getattr(annotation, '__module__', None) == 'typing':
|
||||
return repr(annotation).replace('typing.', '')
|
||||
if isinstance(annotation, types.GenericAlias):
|
||||
return str(annotation)
|
||||
if isinstance(annotation, type):
|
||||
if annotation.__module__ in ('builtins', base_module):
|
||||
return annotation.__qualname__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue