diff options
author | kj <28750310+Fidget-Spinner@users.noreply.github.com> | 2020-12-24 04:33:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-24 04:33:48 (GMT) |
commit | 73607be68668ab7f4bee53507c8dc7b5a46c9cb4 (patch) | |
tree | 4ec6bb3f178e61b7fc61d979ec65519a4ef1d4bc /Lib/test/test_genericalias.py | |
parent | cc3467a57b61b0e7ef254b36790a1c44b13f2228 (diff) | |
download | cpython-73607be68668ab7f4bee53507c8dc7b5a46c9cb4.zip cpython-73607be68668ab7f4bee53507c8dc7b5a46c9cb4.tar.gz cpython-73607be68668ab7f4bee53507c8dc7b5a46c9cb4.tar.bz2 |
bpo-41559: Implement PEP 612 - Add ParamSpec and Concatenate to typing (#23702)
Diffstat (limited to 'Lib/test/test_genericalias.py')
-rw-r--r-- | Lib/test/test_genericalias.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index ccf40b1..fd024dc 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -369,6 +369,27 @@ class BaseTest(unittest.TestCase): self.assertEqual(c1.__args__, c2.__args__) self.assertEqual(hash(c1.__args__), hash(c2.__args__)) + with self.subTest("Testing ParamSpec uses"): + P = typing.ParamSpec('P') + C1 = Callable[P, T] + # substitution + self.assertEqual(C1[int, str], Callable[[int], str]) + self.assertEqual(C1[[int, str], str], Callable[[int, str], str]) + self.assertEqual(repr(C1).split(".")[-1], "Callable[~P, ~T]") + self.assertEqual(repr(C1[int, str]).split(".")[-1], "Callable[[int], str]") + + C2 = Callable[P, int] + # special case in PEP 612 where + # X[int, str, float] == X[[int, str, float]] + self.assertEqual(C2[int, str, float], C2[[int, str, float]]) + self.assertEqual(repr(C2).split(".")[-1], "Callable[~P, int]") + self.assertEqual(repr(C2[int, str]).split(".")[-1], "Callable[[int, str], int]") + + with self.subTest("Testing Concatenate uses"): + P = typing.ParamSpec('P') + C1 = Callable[typing.Concatenate[int, P], int] + self.assertEqual(repr(C1), "collections.abc.Callable" + "[typing.Concatenate[int, ~P], int]") if __name__ == "__main__": unittest.main() |