Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify callable overlap logic #14174

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down