From 1eba4e8552f54413a319c55b57b7298d83839c56 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 23 Nov 2022 13:14:35 +0000 Subject: [PATCH] Simplify callable overlap logic --- mypy/meet.py | 19 +++++++------------ mypy/subtypes.py | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/mypy/meet.py b/mypy/meet.py index f5cd4c1208da..5c187eeb37d4 100644 --- a/mypy/meet.py +++ b/mypy/meet.py @@ -438,18 +438,13 @@ def _type_object_overlap(left: Type, right: Type) -> bool: return _type_object_overlap(left, right) or _type_object_overlap(right, left) if isinstance(left, CallableType) and isinstance(right, CallableType): - - def _callable_overlap(left: CallableType, right: CallableType) -> bool: - return is_callable_compatible( - left, - right, - is_compat=_is_overlapping_types, - ignore_pos_arg_names=True, - allow_partial_overlap=True, - ) - - # Compare both directions to handle type objects. - return _callable_overlap(left, right) or _callable_overlap(right, left) + return is_callable_compatible( + left, + right, + is_compat=_is_overlapping_types, + ignore_pos_arg_names=True, + allow_partial_overlap=True, + ) elif isinstance(left, CallableType): left = left.fallback elif isinstance(right, CallableType): diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 14109587191c..a4b045cfa00c 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -1361,7 +1361,7 @@ def g(x: int) -> int: ... ignore_pos_arg_names = True # Non-type cannot be a subtype of type. - if right.is_type_obj() and not left.is_type_obj(): + if right.is_type_obj() and not left.is_type_obj() and not allow_partial_overlap: return False # A callable L is a subtype of a generic callable R if L is a