Skip to content

Commit

Permalink
Check right operand of is expressions (#4243)
Browse files Browse the repository at this point in the history
The right operand of `is` expressions were not being checked.
Fixes #4055
  • Loading branch information
ethanhs authored and gvanrossum committed Nov 14, 2017
1 parent 9587bfa commit 1cbab17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/checkexpr.py
Expand Up @@ -1395,7 +1395,7 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type:
method_type = None # type: Optional[mypy.types.Type]

if operator == 'in' or operator == 'not in':
right_type = self.accept(right) # TODO only evaluate if needed
right_type = self.accept(right) # always validate the right operand

# Keep track of whether we get type check errors (these won't be reported, they
# are just to verify whether something is valid typing wise).
Expand Down Expand Up @@ -1429,6 +1429,7 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type:
allow_reverse=True)

elif operator == 'is' or operator == 'is not':
self.accept(right) # validate the right operand
sub_result = self.bool_type()
method_type = None
else:
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-expressions.test
Expand Up @@ -613,6 +613,13 @@ class A: pass
[out]
main:3: error: Incompatible types in assignment (expression has type "bool", variable has type "A")

[case testIsRightOperand]

1 is 1()
[builtins fixtures/bool.pyi]
[out]
main:2: error: "int" not callable

[case testReverseBinaryOperator]

class A:
Expand Down

0 comments on commit 1cbab17

Please sign in to comment.