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
Suppress errors for unreachable branches in conditional expressions (#18295)
Fixes#4134Fixes#9195
Suppress errors when analyzing unreachable conditional expression
branches. Same idea as what's done when analyzing the right-hand operand
of `and`/`or`:
https://github.com/python/mypy/blob/973618a6bfa88398e08dc250c8427b381b3a0fce/mypy/checkexpr.py#L4252-L4256
This PR originally added filters of the same form to the places where
`analyze_cond_branch` is called in
`ExpressionChecker.visit_conditional_expr`. However, since 5 out of the
6 `analyze_cond_branch` call sites now use `filter_errors` for the case
when `map is None`, I decided to move the error filtering logic to
inside `analyze_cond_branch`.
**Given:**
```python
from typing import TypeVar
T = TypeVar("T", int, str)
def foo(x: T) -> T:
return x + 1 if isinstance(x, int) else x + "a"
```
**Before:**
```none
main.py:5:16: error: Unsupported operand types for + ("str" and "int") [operator]
main.py:5:49: error: Unsupported operand types for + ("int" and "str") [operator]
Found 2 errors in 1 file (checked 1 source file)
```
**After:**
```
Success: no issues found in 1 source file
```
0 commit comments