bpo-45438: format of inspect.Signature with generic builtins (#29212) · python/cpython@d02ffd1 · GitHub
Skip to content

Commit d02ffd1

Browse files
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>
1 parent 10bbd41 commit d02ffd1

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/inspect.py

Lines changed: 2 additions & 0 deletions

Lib/test/test_inspect.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,17 @@ def foo():
32363236
pass
32373237
self.assertEqual(str(inspect.signature(foo)), '()')
32383238

3239+
def foo(a: list[str]) -> tuple[str, float]:
3240+
pass
3241+
self.assertEqual(str(inspect.signature(foo)),
3242+
'(a: list[str]) -> tuple[str, float]')
3243+
3244+
from typing import Tuple
3245+
def foo(a: list[str]) -> Tuple[str, float]:
3246+
pass
3247+
self.assertEqual(str(inspect.signature(foo)),
3248+
'(a: list[str]) -> Tuple[str, float]')
3249+
32393250
def test_signature_str_positional_only(self):
32403251
P = inspect.Parameter
32413252
S = inspect.Signature
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)