@@ -377,24 +377,34 @@ def visit_instance(self, t: Instance) -> ProperType:
377377 return self .default (self .s )
378378
379379 def visit_callable_type (self , t : CallableType ) -> ProperType :
380- if isinstance (self .s , CallableType ) and is_similar_callables (t , self .s ):
381- if is_equivalent (t , self .s ):
382- return combine_similar_callables (t , self .s )
383- result = join_similar_callables (t , self .s )
384- # We set the from_type_type flag to suppress error when a collection of
385- # concrete class objects gets inferred as their common abstract superclass.
386- if not (
387- (t .is_type_obj () and t .type_object ().is_abstract )
388- or (self .s .is_type_obj () and self .s .type_object ().is_abstract )
389- ):
390- result .from_type_type = True
391- if any (
392- isinstance (tp , (NoneType , UninhabitedType ))
393- for tp in get_proper_types (result .arg_types )
394- ):
395- # We don't want to return unusable Callable, attempt fallback instead.
380+ if isinstance (self .s , CallableType ):
381+ if is_similar_callables (t , self .s ):
382+ if is_equivalent (t , self .s ):
383+ return combine_similar_callables (t , self .s )
384+ result = join_similar_callables (t , self .s )
385+ if any (
386+ isinstance (tp , (NoneType , UninhabitedType ))
387+ for tp in get_proper_types (result .arg_types )
388+ ):
389+ # We don't want to return unusable Callable, attempt fallback instead.
390+ return join_types (t .fallback , self .s )
391+ # We set the from_type_type flag to suppress error when a collection of
392+ # concrete class objects gets inferred as their common abstract superclass.
393+ if not (
394+ (t .is_type_obj () and t .type_object ().is_abstract )
395+ or (self .s .is_type_obj () and self .s .type_object ().is_abstract )
396+ ):
397+ result .from_type_type = True
398+ return result
399+ else :
400+ s2 , t2 = self .s , t
401+ if t2 .is_var_arg :
402+ s2 , t2 = t2 , s2
403+ if is_subtype (s2 , t2 ):
404+ return t2 .copy_modified ()
405+ elif is_subtype (t2 , s2 ):
406+ return s2 .copy_modified ()
396407 return join_types (t .fallback , self .s )
397- return result
398408 elif isinstance (self .s , Overloaded ):
399409 # Switch the order of arguments to that we'll get to visit_overloaded.
400410 return join_types (t , self .s )
0 commit comments