File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
Original file line number Diff line number Diff line change 7
7
by PEP 649. Patches by Jelle Zijlstra and Alex Waygood.
8
8
- Copy the coroutine status of functions and methods wrapped
9
9
with ` @typing_extensions.deprecated ` . Patch by Sebastian Rittau.
10
+ - Fix bug where ` TypeAliasType ` instances could be subscripted even
11
+ where they were not generic. Patch by [ Daraan] ( https://github.com/Daraan ) .
10
12
11
13
# Release 4.12.2 (June 7, 2024)
12
14
Original file line number Diff line number Diff line change @@ -7247,6 +7247,20 @@ def test_getitem(self):
7247
7247
self .assertEqual (get_args (fully_subscripted ), (Iterable [float ],))
7248
7248
self .assertIs (get_origin (fully_subscripted ), ListOrSetT )
7249
7249
7250
+ def test_subscription_without_type_params (self ):
7251
+ Simple = TypeAliasType ("Simple" , int )
7252
+ with self .assertRaises (TypeError , msg = "Only generic type aliases are subscriptable" ):
7253
+ Simple [int ]
7254
+
7255
+ # A TypeVar in the value does not allow subscription
7256
+ T = TypeVar ('T' )
7257
+ MissingTypeParamsErr = TypeAliasType ("MissingTypeParamsErr" , List [T ])
7258
+ self .assertEqual (MissingTypeParamsErr .__type_params__ , ())
7259
+ self .assertEqual (MissingTypeParamsErr .__parameters__ , ())
7260
+ with self .assertRaises (TypeError , msg = "Only generic type aliases are subscriptable" ):
7261
+ MissingTypeParamsErr [int ]
7262
+
7263
+
7250
7264
def test_pickle (self ):
7251
7265
global Alias
7252
7266
Alias = TypeAliasType ("Alias" , int )
Original file line number Diff line number Diff line change @@ -3525,6 +3525,8 @@ def __repr__(self) -> str:
3525
3525
return self .__name__
3526
3526
3527
3527
def __getitem__ (self , parameters ):
3528
+ if not self .__type_params__ :
3529
+ raise TypeError ("Only generic type aliases are subscriptable" )
3528
3530
if not isinstance (parameters , tuple ):
3529
3531
parameters = (parameters ,)
3530
3532
parameters = [
You can’t perform that action at this time.
0 commit comments