mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-118772: Allow TypeVars without a default to follow those with a default when constructing aliases (#118774)
This commit is contained in:
parent
6d419db10c
commit
aac6b019fe
3 changed files with 34 additions and 10 deletions
|
@ -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])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue