Skip to content
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
10 changes: 8 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
)
from mypy.typetraverser import TypeTraverserVisitor
from mypy.nodes import (
TypeInfo, Context, MypyFile, op_methods, FuncDef, reverse_builtin_aliases,
TypeInfo, Context, MypyFile, op_methods, op_methods_to_symbols,
FuncDef, reverse_builtin_aliases,
ARG_POS, ARG_OPT, ARG_NAMED, ARG_NAMED_OPT, ARG_STAR, ARG_STAR2,
ReturnStmt, NameExpr, Var, CONTRAVARIANT, COVARIANT, SymbolNode,
CallExpr
Expand Down Expand Up @@ -353,7 +354,7 @@ def incompatible_argument(self,
else:
base = extract_type(name)

for op, method in op_methods.items():
for method, op in op_methods_to_symbols.items():
for variant in method, '__r' + method[2:]:
# FIX: do not rely on textual formatting
if name.startswith('"{}" of'.format(variant)):
Expand All @@ -366,6 +367,11 @@ def incompatible_argument(self,
context, code=codes.OPERATOR)
return codes.OPERATOR

if name.startswith('"__cmp__" of'):
self.unsupported_operand_types("comparison", arg_type, base,
context, code=codes.OPERATOR)
return codes.INDEX

if name.startswith('"__getitem__" of'):
self.invalid_index_type(arg_type, callee.arg_types[n - 1], base, context,
code=codes.INDEX)
Expand Down
11 changes: 8 additions & 3 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,15 @@ class B:

a, b, c, bo = None, None, None, None # type: (A, B, C, bool)
bo = a == a # E: Unsupported operand types for == ("A" and "A")
bo = a != a # E: Argument 1 to "__cmp__" of "A" has incompatible type "A"; expected "B"
bo = a != a # E: Unsupported operand types for comparison ("A" and "A")
bo = a < b
bo = a > b
bo = b <= b
bo = b <= c
bo = b >= c # E: Argument 1 to "__cmp__" of "B" has incompatible type "C"; expected "B"
bo = b >= c # E: Unsupported operand types for comparison ("C" and "B")
bo = a >= b
bo = c >= b
bo = c <= b # E: Argument 1 to "__cmp__" of "C" has incompatible type "B"; expected "A"
bo = c <= b # E: Unsupported operand types for comparison ("B" and "C")
bo = a == c
bo = b == c # E: Unsupported operand types for == ("C" and "B")

Expand Down Expand Up @@ -510,6 +510,11 @@ class C:

[builtins_py2 fixtures/bool_py2.pyi]

[case testDiv_python2]
10 / 'no' # E: Unsupported operand types for / ("int" and "str")
'no' / 10 # E: Unsupported operand types for / ("str" and "int")
[builtins_py2 fixtures/ops.pyi]

[case cmpIgnoredPy3]

a, b, bo = None, None, None # type: (A, B, bool)
Expand Down