File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 152152from mypy .patterns import AsPattern , StarredPattern
153153from mypy .plugin import Plugin
154154from mypy .plugins import dataclasses as dataclasses_plugin
155+ from mypy .reachability import infer_condition_value , MYPY_TRUE , MYPY_FALSE
155156from mypy .scope import Scope
156157from mypy .semanal import is_trivial_body , refers_to_fullname , set_callable_name
157158from mypy .semanal_enum import ENUM_BASES , ENUM_SPECIAL_PROPS
@@ -5045,7 +5046,7 @@ def _visit_if_stmt_redundant_expr_helper(
50455046
50465047 if codes .REDUNDANT_EXPR not in self .options .enabled_error_codes :
50475048 return
5048- if refers_to_fullname (expr , ( "typing.TYPE_CHECKING" , "typing_extensions.TYPE_CHECKING" ) ):
5049+ if infer_condition_value (expr , self . options ) in ( MYPY_FALSE , MYPY_TRUE ):
50495050 return
50505051
50515052 def _filter (body : Block | None ) -> bool :
Original file line number Diff line number Diff line change @@ -3080,6 +3080,16 @@ while False: # E: While condition is always false
30803080
30813081[builtins fixtures/bool.pyi]
30823082
3083+ [case testNoRedundantExpressionWarningsForUsagesOfTYPECHECKING]
3084+ # flags: --enable-error-code=redundant-expr
3085+ from typing import TYPE_CHECKING
3086+
3087+ if TYPE_CHECKING:
3088+ ...
3089+
3090+ if not TYPE_CHECKING:
3091+ ...
3092+
30833093[case testNoRedundantExpressionWarningsForExhaustivenessChecks]
30843094# flags: --enable-error-code=redundant-expr
30853095from typing import Literal, Never, NoReturn
You can’t perform that action at this time.
0 commit comments