@@ -187,6 +187,16 @@ def _is_type_alias_type(obj: typing.Any) -> bool:
187187 )
188188
189189
190+ def _apply_type (base , args ):
191+ # Some type aliases (like Final) get mad if they get a 1-ary tuple...
192+ # TODO: Should we special case 0?
193+ # (Should we fill in Anys???)
194+ if len (args ) == 1 :
195+ return base [args [0 ]]
196+ else :
197+ return base [* args ]
198+
199+
190200def _eval_types (obj : typing .Any , ctx : EvalContext ):
191201 # Found a recursive alias, we need to unwind it
192202 if obj in ctx .alias_stack :
@@ -285,7 +295,7 @@ def _eval_applied_type_alias(obj: types.GenericAlias, ctx: EvalContext):
285295 """
286296 new_args = tuple (_eval_types (arg , ctx ) for arg in obj .__args__ )
287297
288- new_obj = obj .__origin__ [ new_args ] # type: ignore[index]
298+ new_obj = _apply_type ( obj .__origin__ , new_args )
289299 if isinstance (obj .__origin__ , type ):
290300 # This is a GenericAlias over a Python class, e.g. `dict[str, int]`
291301 # Let's reconstruct it by evaluating all arguments
@@ -326,7 +336,7 @@ def _eval_applied_class(obj: typing_GenericAlias, ctx: EvalContext):
326336 # return _eval_types(ret, ctx) # ???
327337 return ret
328338 else :
329- return obj .__origin__ [ new_args ] # type: ignore[index]
339+ return _apply_type ( obj .__origin__ , new_args )
330340
331341
332342@_eval_types_impl .register
@@ -341,7 +351,7 @@ def _eval_ty_or_list(obj):
341351
342352 new_args = tuple (_eval_ty_or_list (arg ) for arg in typing .get_args (obj ))
343353 # origin for Callable is collections.abc.Callable which kind of annoying
344- return typing .Callable [ * new_args ]
354+ return _apply_type ( typing .Callable , new_args )
345355
346356
347357@_eval_types_impl .register
0 commit comments