Skip to content

--strict-equality too strict in iteratively visited code #19328

Description

@tyralla

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-equalityx=1whileTrue:
ifx==str(): # error: Non-overlapping equality check (left operand type: "A", right operand type: "C")breakx=str()
ifx==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-equalityclassA: ...
classB: ...
classC: ...
x=A()
whileTrue:
ifx==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")breakx=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.

Metadata

Metadata

Assignees

Labels

bugmypy got something wrongtopic-overlapOverlapping equality check

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions