You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
deffoo(x: int|None, y: str|None) ->None:
ifxisy:
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
The text was updated successfully, but these errors were encountered:
It was decided when --strict-equality was implemented that (according to #6370) "Optional[X] and Optional[Y] are non-overlapping if X and Y are non-overlapping".
In my opinion, the documented reason "although technically None is overlap, it is most likely an error" is not very convincing, and we would all benefit from the change if the corner case was removed.
I'm not sure if I understand correctly, but this restriction was originally added to account for type promotions? Now that we don't ignore promotions anymore (#6674), we really should change this.
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 asx
andy
are optional.To Reproduce
Actual Behavior
Your Environment
--strict
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: