-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress errors for unreachable branches in conditional expressions (#…
…18295) Fixes #4134 Fixes #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 ```
- Loading branch information
1 parent
d33cef8
commit 7959a20
Showing
3 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters