@@ -2865,7 +2865,7 @@ def infer_overload_return_type(
28652865 matches : list [CallableType ] = []
28662866 return_types : list [Type ] = []
28672867 inferred_types : list [Type ] = []
2868- args_contain_any = any (map ( has_any_type , arg_types ) )
2868+ args_contain_any = any (has_any_type ( a , include_special_form = True ) for a in arg_types )
28692869 type_maps : list [dict [Expression , Type ]] = []
28702870
28712871 for typ in plausible_targets :
@@ -5977,7 +5977,7 @@ def accept(
59775977 ):
59785978 self .msg .disallowed_any_type (typ , node )
59795979
5980- if not self .chk .in_checked_function () or self . chk . current_node_deferred :
5980+ if not self .chk .in_checked_function ():
59815981 result : Type = AnyType (TypeOfAny .unannotated )
59825982 else :
59835983 result = typ
@@ -6311,19 +6311,29 @@ def has_abstract_type(self, caller_type: ProperType, callee_type: ProperType) ->
63116311 )
63126312
63136313
6314- def has_any_type (t : Type , ignore_in_type_obj : bool = False ) -> bool :
6314+ def has_any_type (
6315+ t : Type , ignore_in_type_obj : bool = False , include_special_form : bool = False
6316+ ) -> bool :
63156317 """Whether t contains an Any type"""
6316- return t .accept (HasAnyType (ignore_in_type_obj ))
6318+ return t .accept (HasAnyType (ignore_in_type_obj , include_special_form ))
63176319
63186320
63196321class HasAnyType (types .BoolTypeQuery ):
6320- def __init__ (self , ignore_in_type_obj : bool ) -> None :
6322+ def __init__ (self , ignore_in_type_obj : bool , include_special_form : bool ) -> None :
63216323 super ().__init__ (types .ANY_STRATEGY )
63226324 self .ignore_in_type_obj = ignore_in_type_obj
6325+ self .include_special_form = include_special_form
63236326
63246327 def visit_any (self , t : AnyType ) -> bool :
6328+ if self .include_special_form :
6329+ return True
63256330 return t .type_of_any != TypeOfAny .special_form # special forms are not real Any types
63266331
6332+ def visit_tuple_type (self , t : TupleType ) -> bool :
6333+ # TODO: should we use tuple_fallback() in (Bool)TypeQuery itself?
6334+ # Using partial_fallback is error prone as it may be bogus (hence the name).
6335+ return self .query_types (t .items + [tuple_fallback (t )])
6336+
63276337 def visit_callable_type (self , t : CallableType ) -> bool :
63286338 if self .ignore_in_type_obj and t .is_type_obj ():
63296339 return False
@@ -6547,7 +6557,7 @@ def any_causes_overload_ambiguity(
65476557 # We ignore Anys in type object callables as ambiguity
65486558 # creators, since that can lead to falsely claiming ambiguity
65496559 # for overloads between Type and Callable.
6550- if has_any_type (arg_type , ignore_in_type_obj = True ):
6560+ if has_any_type (arg_type , ignore_in_type_obj = True , include_special_form = True ):
65516561 matching_formals_unfiltered = [
65526562 (item_idx , lookup [arg_idx ])
65536563 for item_idx , lookup in enumerate (actual_to_formal )
0 commit comments