Open
Description
Bug Report
mypy generates "error: Non-overlapping identity check" for identity comparison between optionals, even though None has the same identity as None. This is especially confusing for the x is y is None
pattern, which I would expect to be valid as long as x
and y
are optional.
To Reproduce
def foo(x: int | None, y: str | None) -> None:
if x is y:
print('x and y have same identity!')
foo(None, None)
Actual Behavior
$ python repr.py
x and y have same identity!
$ mypy --strict repr.py
repr.py:2: error: Non-overlapping identity check (left operand type: "Optional[int]", right operand type: "Optional[str]") [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.991
- Mypy command-line flags:
--strict
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10.8