Skip to content

Merge subtype visitors #13303

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

Merged
merged 12 commits into from
Aug 3, 2022
23 changes: 14 additions & 9 deletions mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
"""Special cases for type object types overlaps."""
# TODO: these checks are a bit in gray area, adjust if they cause problems.
left, right = get_proper_types((left, right))
# 1. Type[C] vs Callable[..., C], where the latter is class object.
if isinstance(left, TypeType) and isinstance(right, CallableType) and right.is_type_obj():
# 1. Type[C] vs Callable[..., C] overlap even if the latter is not class object.
if isinstance(left, TypeType) and isinstance(right, CallableType):
return _is_overlapping_types(left.item, right.ret_type)
# 2. Type[C] vs Meta, where Meta is a metaclass for C.
if isinstance(left, TypeType) and isinstance(right, Instance):
Expand All @@ -381,13 +381,18 @@ 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):
return is_callable_compatible(
left,
right,
is_compat=_is_overlapping_types,
ignore_pos_arg_names=True,
allow_partial_overlap=True,
)

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)
elif isinstance(left, CallableType):
left = left.fallback
elif isinstance(right, CallableType):
Expand Down
Loading