Skip to content

Commit 86974b1

Browse files
committed
Merge pull request #1122 from JukkaL/fix1121
Fix crash in check_overlapping_op_methods(). Fix #1121.
2 parents f121947 + 2b58c5f commit 86974b1

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

mypy/checker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,8 @@ def check_overlapping_op_methods(self,
711711
self.check_overlapping_op_methods(
712712
reverse_type, reverse_name, reverse_class,
713713
item, forward_name, forward_base, context)
714-
else:
715-
# TODO what about this?
716-
assert False, 'Forward operator method type is not CallableType'
714+
elif not isinstance(forward_type, AnyType):
715+
self.msg.forward_operator_not_callable(forward_name, context)
717716

718717
def check_inplace_operator_method(self, defn: FuncBase) -> None:
719718
"""Check an inplace operator method such as __iadd__.

mypy/messages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,11 @@ def operator_method_signatures_overlap(
777777
forward_method, forward_class),
778778
context)
779779

780+
def forward_operator_not_callable(
781+
self, forward_method: str, context: Context) -> None:
782+
self.fail('Forward operator "{}" is not callable'.format(
783+
forward_method), context)
784+
780785
def signatures_incompatible(self, method: str, other_method: str,
781786
context: Context) -> None:
782787
self.fail('Signatures of "{}" and "{}" are incompatible'.format(

mypy/test/data/check-classes.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,33 @@ class C:
10151015
def __radd__(self, x: Any) -> int: pass
10161016
[out]
10171017

1018+
[case testReverseOperatorMethodForwardIsAny]
1019+
from typing import Any
1020+
def deco(f: Any) -> Any: return f
1021+
class C:
1022+
@deco
1023+
def __add__(self, other: C) -> C: return C()
1024+
def __radd__(self, other: C) -> C: return C()
1025+
[out]
1026+
1027+
[case testReverseOperatorMethodForwardIsAny2]
1028+
from typing import Any
1029+
def deco(f: Any) -> Any: return f
1030+
class C:
1031+
__add__ = None # type: Any
1032+
def __radd__(self, other: C) -> C: return C()
1033+
[out]
1034+
1035+
[case testReverseOperatorMethodForwardIsAny3]
1036+
from typing import Any
1037+
def deco(f: Any) -> Any: return f
1038+
class C:
1039+
__add__ = 42
1040+
def __radd__(self, other: C) -> C: return C()
1041+
[out]
1042+
main: note: In member "__radd__" of class "C":
1043+
main:5: error: Forward operator "__add__" is not callable
1044+
10181045
[case testOverloadedReverseOperatorMethodArgumentType]
10191046
from typing import overload, Any
10201047
class A:

0 commit comments

Comments
 (0)