@@ -306,6 +306,19 @@ def is_none_object_overlap(t1: ProperType, t2: ProperType) -> bool:
306306 )
307307
308308
309+ def are_related_types (
310+ left : Type , right : Type , * , proper_subtype : bool , ignore_promotions : bool
311+ ) -> bool :
312+ if proper_subtype :
313+ return is_proper_subtype (
314+ left , right , ignore_promotions = ignore_promotions
315+ ) or is_proper_subtype (right , left , ignore_promotions = ignore_promotions )
316+ else :
317+ return is_subtype (left , right , ignore_promotions = ignore_promotions ) or is_subtype (
318+ right , left , ignore_promotions = ignore_promotions
319+ )
320+
321+
309322def is_overlapping_types (
310323 left : Type ,
311324 right : Type ,
@@ -385,16 +398,10 @@ def is_overlapping_types(
385398 if is_none_object_overlap (left , right ) or is_none_object_overlap (right , left ):
386399 return False
387400
388- if overlap_for_overloads :
389- if is_proper_subtype (
390- left , right , ignore_promotions = ignore_promotions
391- ) or is_proper_subtype (right , left , ignore_promotions = ignore_promotions ):
392- return True
393- else :
394- if is_subtype (left , right , ignore_promotions = ignore_promotions ) or is_subtype (
395- right , left , ignore_promotions = ignore_promotions
396- ):
397- return True
401+ if are_related_types (
402+ left , right , proper_subtype = overlap_for_overloads , ignore_promotions = ignore_promotions
403+ ):
404+ return True
398405
399406 # See the docstring for 'get_possible_variants' for more info on what the
400407 # following lines are doing.
@@ -567,16 +574,10 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
567574 if isinstance (left , Instance ) and isinstance (right , Instance ):
568575 # First we need to handle promotions and structural compatibility for instances
569576 # that came as fallbacks, so simply call is_subtype() to avoid code duplication.
570- if overlap_for_overloads :
571- if is_proper_subtype (
572- left , right , ignore_promotions = ignore_promotions
573- ) or is_proper_subtype (right , left , ignore_promotions = ignore_promotions ):
574- return True
575- else :
576- if is_subtype (left , right , ignore_promotions = ignore_promotions ) or is_subtype (
577- right , left , ignore_promotions = ignore_promotions
578- ):
579- return True
577+ if are_related_types (
578+ left , right , proper_subtype = overlap_for_overloads , ignore_promotions = ignore_promotions
579+ ):
580+ return True
580581
581582 if right .type .fullname == "builtins.int" and left .type .fullname in MYPYC_NATIVE_INT_NAMES :
582583 return True
0 commit comments