Open
Description
The second error report is good, but, in line with the decision made in #6735, the first one is not:
# flags: --allow-redefinition-new --local-partial-types --strict-equality
x = 1
while True:
if x == str(): # error: Non-overlapping equality check (left operand type: "A", right operand type: "C")
break
x = str()
if x == int(): # error: Non-overlapping equality check (left operand type: "str", right operand type: "int")
break
This could be easily fixed by letting the IterationErrorWatcher
also handle COMPARISON_OVERLAP
errors (which would already be an improvement over the current handling of functions with constrained type variables of just turning off --strict-equality
temporarily). However, IterationErrorWatcher
would need some adjustments to not accidentally filter out errors with slightly different texts, like in this case:
# flags: --allow-redefinition-new --local-partial-types --strict-equality
class A: ...
class B: ...
class C: ...
x = A()
while True:
if x == C(): # error: Non-overlapping equality check (left operand type: "A", right operand type: "C")
# error: Non-overlapping equality check (left operand type: "A | B", right operand type: "C")
break
x = B()
Ideally, Mypy would only emit the last report (with A | B
), which could eventually be implemented similarly to what is suggested in #19324 for reveal_type
.