Skip to content

Commit 5bc1360

Browse files
committed
3.8, 3.9 use collected parameters more explicitly
minor comment corrections
1 parent b8799ce commit 5bc1360

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/test_typing_extensions.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7203,11 +7203,9 @@ def test_alias_types_and_substitutions(self):
72037203
Unpack[Ts] : (Ts,),
72047204
Unpack[Tuple[int, T2]] : (T2,),
72057205
Concatenate[int, P] : (P,),
7206+
# Not tested usage of bare TypeVarTuple, would need 3.11+
7207+
# Ts : (Ts,), # invalid case
72067208
}
7207-
test_argument_cases_311_plus = {
7208-
Ts : (Ts,), # invalid case
7209-
}
7210-
test_argument_cases.update(test_argument_cases_311_plus)
72117209

72127210
test_alias_cases = [
72137211
# Simple cases
@@ -7241,8 +7239,6 @@ def test_alias_types_and_substitutions(self):
72417239
self.assertEqual(subscripted.__parameters__, ())
72427240
for expected_args, expected_parameters in test_argument_cases.items():
72437241
with self.subTest(alias=alias, args=expected_args):
7244-
if expected_args in test_argument_cases_311_plus and sys.version_info < (3, 11):
7245-
self.skipTest("Case is not valid before 3.11")
72467242
self.assertEqual(get_args(alias[expected_args]), (expected_args,))
72477243
self.assertEqual(alias[expected_args].__parameters__, expected_parameters)
72487244

@@ -7419,9 +7415,9 @@ def test_wrong_amount_of_parameters(self):
74197415
self.assertEqual(get_args(alias), expected_args)
74207416
self.assertEqual(alias.__parameters__, expected_params)
74217417

7422-
# The condition should align with the version of GeneriAlias usage in __getitem__
7418+
# The condition should align with the version of GeneriAlias usage in __getitem__ or be 3.11+
74237419
@skipIf(TYPING_3_10_0, "Most arguments are allowed in 3.11+ or with GenericAlias")
7424-
def test_invalid_cases_before_3_11(self):
7420+
def test_invalid_cases_before_3_10(self):
74257421
T = TypeVar('T')
74267422
ListOrSetT = TypeAliasType("ListOrSetT", Union[List[T], Set[T]], type_params=(T,))
74277423
with self.assertRaises(TypeError):

src/typing_extensions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,7 +3577,7 @@ def _check_single_param(self, param, recursion=0):
35773577
# Allow [], [int], [int, str], [int, ...], [int, T]
35783578
if param is ...:
35793579
yield ...
3580-
# Note in < 3.9 _ConcatenateGenericAlias inherits from list
3580+
# Note in <= 3.9 _ConcatenateGenericAlias inherits from list
35813581
elif isinstance(param, list) and recursion == 0:
35823582
yield [checked
35833583
for arg in param
@@ -3611,9 +3611,10 @@ def __getitem__(self, parameters):
36113611
type_vars = _collect_type_vars(parameters)
36123612
parameters = self._check_parameters(parameters)
36133613
alias = _TypeAliasGenericAlias(self, parameters)
3614-
# If Concatenate is present its parameters were not collected
3615-
if len(alias.__parameters__) < len(type_vars):
3616-
alias.__parameters__ = tuple(type_vars)
3614+
# alias.__parameters__ is not complete if Concatenate is present
3615+
# as it is converted to a list from which no parameters are extracted.
3616+
if alias.__parameters__ != type_vars:
3617+
alias.__parameters__ = type_vars
36173618
return alias
36183619

36193620
def __reduce__(self):

0 commit comments

Comments
 (0)