gh-102615: Use `list` instead of `tuple` in `repr` of paramspec (#102… · python/cpython@2b5781d · GitHub
Skip to content

Commit 2b5781d

Browse files
gh-102615: Use list instead of tuple in repr of paramspec (#102637)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 8647ba4 commit 2b5781d

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

Lib/test/test_typing.py

Lines changed: 45 additions & 0 deletions

Lib/typing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,17 @@ def _type_repr(obj):
230230
typically enough to uniquely identify a type. For everything
231231
else, we fall back on repr(obj).
232232
"""
233-
if isinstance(obj, types.GenericAlias):
234-
return repr(obj)
235233
if isinstance(obj, type):
236234
if obj.__module__ == 'builtins':
237235
return obj.__qualname__
238236
return f'{obj.__module__}.{obj.__qualname__}'
239237
if obj is ...:
240-
return('...')
238+
return '...'
241239
if isinstance(obj, types.FunctionType):
242240
return obj.__name__
241+
if isinstance(obj, tuple):
242+
# Special case for `repr` of types with `ParamSpec`:
243+
return '[' + ', '.join(_type_repr(t) for t in obj) + ']'
243244
return repr(obj)
244245

245246

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)