Skip to content

Commit 6115d9a

Browse files
committed
Disallow assignment of protocol or abstract classes to Callable
1 parent fa01a07 commit 6115d9a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mypy/subtypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,11 @@ def g(x: int) -> int: ...
15331533
if right.is_type_obj() and not left.is_type_obj() and not allow_partial_overlap:
15341534
return False
15351535

1536+
if left.is_type_obj():
1537+
left_type_obj = left.type_object()
1538+
if (left_type_obj.is_protocol or left_type_obj.is_abstract) and not right.is_type_obj():
1539+
return False
1540+
15361541
# A callable L is a subtype of a generic callable R if L is a
15371542
# subtype of every type obtained from R by substituting types for
15381543
# the variables of R. We can check this by simply leaving the

0 commit comments

Comments
 (0)