bpo-45438: format of inspect.Signature with generic builtins (GH-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>
(cherry picked from commit d02ffd1b5c)

Co-authored-by: Martin Rueckl <enigma@nbubu.de>
This commit is contained in:
Miss Islington (bot) 2021-10-27 15:00:18 -07:00 committed by GitHub
parent 30c1f18ee6
commit 21150c6fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -1233,6 +1233,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__