gh-105486: Change the repr of ParamSpec list of args in GenericAlias (#105488)

This commit is contained in:
Nikita Sobolev 2023-07-01 03:04:50 +03:00 committed by GitHub
parent e212618baf
commit eb7d6e7ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View file

@ -209,6 +209,9 @@ class BaseTest(unittest.TestCase):
def test_repr(self):
class MyList(list):
pass
class MyGeneric:
__class_getitem__ = classmethod(GenericAlias)
self.assertEqual(repr(list[str]), 'list[str]')
self.assertEqual(repr(list[()]), 'list[()]')
self.assertEqual(repr(tuple[int, ...]), 'tuple[int, ...]')
@ -221,6 +224,11 @@ class BaseTest(unittest.TestCase):
self.assertTrue(repr(MyList[int]).endswith('.BaseTest.test_repr.<locals>.MyList[int]'))
self.assertEqual(repr(list[str]()), '[]') # instances should keep their normal repr
# gh-105488
self.assertTrue(repr(MyGeneric[int]).endswith('MyGeneric[int]'))
self.assertTrue(repr(MyGeneric[[]]).endswith('MyGeneric[[]]'))
self.assertTrue(repr(MyGeneric[[int, str]]).endswith('MyGeneric[[int, str]]'))
def test_exposed_type(self):
import types
a = types.GenericAlias(list, int)