mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-41559: Change PEP 612 implementation to pure Python (#25449)
This commit is contained in:
parent
c1a9535989
commit
859577c249
4 changed files with 92 additions and 71 deletions
|
|
@ -353,6 +353,12 @@ class BaseTest(unittest.TestCase):
|
|||
self.assertEqual(repr(C4[dict]).split(".")[-1], "Callable[[int, dict], str]")
|
||||
self.assertEqual(C4[dict], Callable[[int, dict], str])
|
||||
|
||||
# substitute a nested GenericAlias (both typing and the builtin
|
||||
# version)
|
||||
C5 = Callable[[typing.List[T], tuple[K, T], V], int]
|
||||
self.assertEqual(C5[int, str, float],
|
||||
Callable[[typing.List[int], tuple[str, int], float], int])
|
||||
|
||||
with self.subTest("Testing type erasure"):
|
||||
class C1(Callable):
|
||||
def __call__(self):
|
||||
|
|
@ -391,5 +397,16 @@ class BaseTest(unittest.TestCase):
|
|||
self.assertEqual(repr(C1), "collections.abc.Callable"
|
||||
"[typing.Concatenate[int, ~P], int]")
|
||||
|
||||
with self.subTest("Testing TypeErrors"):
|
||||
with self.assertRaisesRegex(TypeError, "variables left in"):
|
||||
alias[int]
|
||||
P = typing.ParamSpec('P')
|
||||
C1 = Callable[P, T]
|
||||
with self.assertRaisesRegex(TypeError, "many arguments for"):
|
||||
C1[int, str, str]
|
||||
with self.assertRaisesRegex(TypeError, "few arguments for"):
|
||||
C1[int]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue