File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 77 by PEP 649. Patches by Jelle Zijlstra and Alex Waygood.
88- Copy the coroutine status of functions and methods wrapped
99 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 ) .
1012
1113# Release 4.12.2 (June 7, 2024)
1214
Original file line number Diff line number Diff line change @@ -7319,6 +7319,20 @@ def test_getitem(self):
73197319 self .assertEqual (get_args (fully_subscripted ), (Iterable [float ],))
73207320 self .assertIs (get_origin (fully_subscripted ), ListOrSetT )
73217321
7322+ def test_subscription_without_type_params (self ):
7323+ Simple = TypeAliasType ("Simple" , int )
7324+ with self .assertRaises (TypeError , msg = "Only generic type aliases are subscriptable" ):
7325+ Simple [int ]
7326+
7327+ # A TypeVar in the value does not allow subscription
7328+ T = TypeVar ('T' )
7329+ MissingTypeParamsErr = TypeAliasType ("MissingTypeParamsErr" , List [T ])
7330+ self .assertEqual (MissingTypeParamsErr .__type_params__ , ())
7331+ self .assertEqual (MissingTypeParamsErr .__parameters__ , ())
7332+ with self .assertRaises (TypeError , msg = "Only generic type aliases are subscriptable" ):
7333+ MissingTypeParamsErr [int ]
7334+
7335+
73227336 def test_pickle (self ):
73237337 global Alias
73247338 Alias = TypeAliasType ("Alias" , int )
Original file line number Diff line number Diff line change @@ -3559,6 +3559,8 @@ def __repr__(self) -> str:
35593559 return self .__name__
35603560
35613561 def __getitem__ (self , parameters ):
3562+ if not self .__type_params__ :
3563+ raise TypeError ("Only generic type aliases are subscriptable" )
35623564 if not isinstance (parameters , tuple ):
35633565 parameters = (parameters ,)
35643566 parameters = [
You can’t perform that action at this time.
0 commit comments