python / python/mypy

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

Open
#11,888 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-overlap
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported snippet with the mypy CLI, starting from the identity-check diagnostic behavior described in the issue. Trace how comparisons against None are handled and add a regression test for a non-optional left operand; done when the None comparison reports a non-overlapping identity check without regressing the existing cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.