mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
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
This commit is contained in:
parent
7565586724
commit
b2f3f8e3d8
3 changed files with 59 additions and 14 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue