`!= (None, None)` Narrowing only in else branch
bugtopic-type-narrowing
**Bug Report**
`!= (None, None)` correctly narrows the else branch to `tuple[None, None]` but, doesn't narrow the union in the if branch.
**To Reproduce**
```python
a: tuple[int, str] | tuple[None, None]
if a != (None, None):
reveal_type(a) # Revealed type is "tuple[int, str] | tuple[None, None]"
else:
reveal_type(a) # Revealed type is "tuple[None, None]"
```
**Expected Behavior**
The if branch should narrow to `tuple[int, str]`
**Actual Behavior**
The if branch is `tuple[int, str] | tuple[None, None]`
**Your Environment**
<!-- Include as many relevant details about the environment you experienced the bug in -->
- Mypy version used: 2.1
- Mypy command-line flags:
- Mypy configuration options from `mypy.ini` (and other config files):
- Python version used:
<!-- You can freely edit this text, please remove all the lines you believe are unnecessary. -->
0 条评论