@@ -4199,18 +4199,24 @@ def narrow_type_from_binder(self, expr: Expression, known_type: Type,
4199
4199
return known_type
4200
4200
4201
4201
4202
- def has_any_type (t : Type ) -> bool :
4202
+ def has_any_type (t : Type , ignore_in_type_obj : bool = False ) -> bool :
4203
4203
"""Whether t contains an Any type"""
4204
- return t .accept (HasAnyType ())
4204
+ return t .accept (HasAnyType (ignore_in_type_obj ))
4205
4205
4206
4206
4207
4207
class HasAnyType (types .TypeQuery [bool ]):
4208
- def __init__ (self ) -> None :
4208
+ def __init__ (self , ignore_in_type_obj : bool ) -> None :
4209
4209
super ().__init__ (any )
4210
+ self .ignore_in_type_obj = ignore_in_type_obj
4210
4211
4211
4212
def visit_any (self , t : AnyType ) -> bool :
4212
4213
return t .type_of_any != TypeOfAny .special_form # special forms are not real Any types
4213
4214
4215
+ def visit_callable_type (self , t : CallableType ) -> bool :
4216
+ if self .ignore_in_type_obj and t .is_type_obj ():
4217
+ return False
4218
+ return super ().visit_callable_type (t )
4219
+
4214
4220
4215
4221
def has_coroutine_decorator (t : Type ) -> bool :
4216
4222
"""Whether t came from a function decorated with `@coroutine`."""
@@ -4408,7 +4414,10 @@ def any_causes_overload_ambiguity(items: List[CallableType],
4408
4414
]
4409
4415
4410
4416
for arg_idx , arg_type in enumerate (arg_types ):
4411
- if has_any_type (arg_type ):
4417
+ # We ignore Anys in type object callables as ambiguity
4418
+ # creators, since that can lead to falsely claiming ambiguity
4419
+ # for overloads between Type and Callable.
4420
+ if has_any_type (arg_type , ignore_in_type_obj = True ):
4412
4421
matching_formals_unfiltered = [(item_idx , lookup [arg_idx ])
4413
4422
for item_idx , lookup in enumerate (actual_to_formal )
4414
4423
if lookup [arg_idx ]]
0 commit comments