gh-118772: Allow TypeVars without a default to follow those with a default when constructing aliases (#118774)

This commit is contained in:
Jelle Zijlstra 2024-05-08 09:54:51 -07:00 committed by GitHub
parent 6d419db10c
commit aac6b019fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 10 deletions

View file

@ -668,6 +668,23 @@ class TypeParameterDefaultsTests(BaseTestCase):
with self.assertRaises(TypeError):
class Y(Generic[*Ts_default, T]): ...
def test_allow_default_after_non_default_in_alias(self):
T_default = TypeVar('T_default', default=int)
T = TypeVar('T')
Ts = TypeVarTuple('Ts')
a1 = Callable[[T_default], T]
self.assertEqual(a1.__args__, (T_default, T))
a2 = dict[T_default, T]
self.assertEqual(a2.__args__, (T_default, T))
a3 = typing.Dict[T_default, T]
self.assertEqual(a3.__args__, (T_default, T))
a4 = Callable[*Ts, T]
self.assertEqual(a4.__args__, (*Ts, T))
def test_paramspec_specialization(self):
T = TypeVar("T")
P = ParamSpec('P', default=[str, int])