diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 9c0e2f4048b3..758d219cfd98 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2762,7 +2762,7 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type: # the analysis from the semanal phase below. We assume that nodes # marked as unreachable during semantic analysis were done so intentionally. # So, we shouldn't report an error. - if self.chk.options.warn_unreachable: + if self.chk.should_report_unreachable_issues(): if right_map is None: self.msg.unreachable_right_operand(e.op, e.right) diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index f5b49d87289a..e95faf503d99 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -925,6 +925,7 @@ from typing import TypeVar, Generic T1 = TypeVar('T1', bound=int) T2 = TypeVar('T2', int, str) +T3 = TypeVar('T3', None, str) def test1(x: T1) -> T1: if isinstance(x, int): @@ -961,6 +962,19 @@ class Test3(Generic[T2]): # Same issue as above reveal_type(self.x) + +class Test4(Generic[T3]): + def __init__(self, x: T3): + # https://github.com/python/mypy/issues/9456 + # On TypeVars with value restrictions, we currently have no way + # of checking a statement for all the type expansions. + # Thus unreachable warnings are disabled + if x and False: + pass + # This test should fail after this limitation is removed. + if False and x: + pass + [builtins fixtures/isinstancelist.pyi] [case testUnreachableFlagContextManagersNoSuppress] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy