10000 gh-102615: Use `list` instead of `tuple` in `repr` of paramspec by sobolevn · Pull Request #102637 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-102615: Use list instead of tuple in repr of paramspec #102637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-102615: Use list instead of tuple in repr of paramspec
  • Loading branch information
sobolevn committed Mar 13, 2023
commit 8e4620cf1e596e714f54579f8ee6721d1cc6982f
20 changes: 20 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,26 @@ class Y(C[int]):
self.assertEqual(Y.__qualname__,
'GenericTests.test_repr_2.<locals>.Y')

def test_repr_3(self):
T = TypeVar('T')
P = ParamSpec('P')

class MyCallable(Generic[P, T]):
pass

self.assertEqual(
repr(MyCallable[[], bool]).split('.')[-1],
'MyCallable[[], bool]',
)
self.assertEqual(
repr(MyCallable[[int], bool]).split('.')[-1],
'MyCallable[[int], bool]',
)
self.assertEqual(
repr(MyCallable[[int, str], bool]).split('.')[-1],
"MyCallable[[int, str], bool]",
)

def test_eq_1(self):
self.assertEqual(Generic, Generic)
self.assertEqual(Generic[T], Generic[T])
Expand Down
5 changes: 4 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,12 @@ def _type_repr(obj):
return obj.__qualname__
return f'{obj.__module__}.{obj.__qualname__}'
if obj is ...:
return('...')
return '...'
if isinstance(obj, types.FunctionType):
return obj.__name__
if isinstance(obj, tuple):
# Special case for `repr` of types with `ParamSpec`:
return '[' + ', '.join(_type_repr(t) for t in obj) + ']'
return repr(obj)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use list instead of tuple 4B2B in ``repr`` of generic aliases with ``ParamSpec``.
0