Skip to content

Commit 07139ef

Browse files
authored
Simplify callable overlap logic (#14174)
This gives around 1% speed-up on self check, and may give even more for code that is heavy on overloads.
1 parent acbc40c commit 07139ef

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

mypy/meet.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,13 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
438438
return _type_object_overlap(left, right) or _type_object_overlap(right, left)
439439

440440
if isinstance(left, CallableType) and isinstance(right, CallableType):
441-
442-
def _callable_overlap(left: CallableType, right: CallableType) -> bool:
443-
return is_callable_compatible(
444-
left,
445-
right,
446-
is_compat=_is_overlapping_types,
447-
ignore_pos_arg_names=True,
448-
allow_partial_overlap=True,
449-
)
450-
451-
# Compare both directions to handle type objects.
452-
return _callable_overlap(left, right) or _callable_overlap(right, left)
441+
return is_callable_compatible(
442+
left,
443+
right,
444+
is_compat=_is_overlapping_types,
445+
ignore_pos_arg_names=True,
446+
allow_partial_overlap=True,
447+
)
453448
elif isinstance(left, CallableType):
454449
left = left.fallback
455450
elif isinstance(right, CallableType):

mypy/subtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ def g(x: int) -> int: ...
13611361
ignore_pos_arg_names = True
13621362

13631363
# Non-type cannot be a subtype of type.
1364-
if right.is_type_obj() and not left.is_type_obj():
1364+
if right.is_type_obj() and not left.is_type_obj() and not allow_partial_overlap:
13651365
return False
13661366

13671367
# A callable L is a subtype of a generic callable R if L is a

0 commit comments

Comments
 (0)