Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-overlapping identity check when left operand is not optional and right operand is None #11888

Open
sami-evangelista opened this issue Jan 2, 2022 · 1 comment
Labels
feature topic-overlap Overlapping equality check

Comments

@sami-evangelista
Copy link

sami-evangelista commented Jan 2, 2022

mypy does not complain on line 4 of this code:

i: int = 1
s: str = 'hi'
i is s  # error: Non-overlapping identity check (left operand type: "int", right operand type: "str")
if i is None: # ok
   ...

would it be possible to raise a Non-overlapping identity check error in that case, as in the previous line?

mypy version:

$ mypy --version
mypy 0.930
@chnmasta05
Copy link

chnmasta05 commented May 31, 2023

I suggest adding the topic-overlap label.

It was decided when --strict-equality was implemented that (according to #6370) "X and None are overlapping even in strict-optional mode".

Current documentation reads:

* X and None are overlapping even in strict-optional mode. This is to allow
'assert x is not None' for x defined as 'x = None  # type: str' in class body
(otherwise mypy itself would have couple dozen errors because of this).

@JelleZijlstra JelleZijlstra added the topic-overlap Overlapping equality check label May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-overlap Overlapping equality check
Projects
None yet
Development

No branches or pull requests

3 participants