summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>2021-05-13 05:24:35 (GMT)
committerGitHub <noreply@github.com>2021-05-13 05:24:35 (GMT)
commitb2f3f8e3d81b0bb0ba18f563d82c28ba133c0790 (patch)
tree53a693312609230211261241053263ac3e5fefcc /Lib/test/test_typing.py
parent7565586724692e2ad164d770af9675f7a261fe3a (diff)
downloadcpython-b2f3f8e3d81b0bb0ba18f563d82c28ba133c0790.zip
cpython-b2f3f8e3d81b0bb0ba18f563d82c28ba133c0790.tar.gz
cpython-b2f3f8e3d81b0bb0ba18f563d82c28ba133c0790.tar.bz2
bpo-44098: Drop ParamSpec from most ``__parameters__`` in typing generics (GH-26013)
Added two new attributes to ``_GenericAlias``: * ``_typevar_types``, a single type or tuple of types indicating what types are treated as a ``TypeVar``. Used for ``isinstance`` checks. * ``_paramspec_tvars ``, a boolean flag which guards special behavior for dealing with ``ParamSpec``. Setting it to ``True`` means this class deals with ``ParamSpec``. Automerge-Triggered-By: GH:gvanrossum
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index a2a5d8f..79c5c3a 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4359,6 +4359,31 @@ class ParamSpecTests(BaseTestCase):
self.assertEqual(C1[int, str], Callable[[int], str])
self.assertEqual(C1[[int, str, dict], float], Callable[[int, str, dict], float])
+ def test_no_paramspec_in__parameters__(self):
+ # ParamSpec should not be found in __parameters__
+ # of generics. Usages outside Callable, Concatenate
+ # and Generic are invalid.
+ T = TypeVar("T")
+ P = ParamSpec("P")
+ self.assertNotIn(P, List[P].__parameters__)
+ self.assertIn(T, Tuple[T, P].__parameters__)
+
+ # Test for consistency with builtin generics.
+ self.assertNotIn(P, list[P].__parameters__)
+ self.assertIn(T, tuple[T, P].__parameters__)
+
+ def test_paramspec_in_nested_generics(self):
+ # Although ParamSpec should not be found in __parameters__ of most
+ # generics, they probably should be found when nested in
+ # a valid location.
+ T = TypeVar("T")
+ P = ParamSpec("P")
+ C1 = Callable[P, T]
+ G1 = List[C1]
+ G2 = list[C1]
+ self.assertEqual(G1.__parameters__, (P, T))
+ self.assertEqual(G2.__parameters__, (P, T))
+
class ConcatenateTests(BaseTestCase):
def test_basics(self):