Skip to content

Commit 83d2f8f

Browse files
committed
Fix redundant-expr error code
1 parent 11915aa commit 83d2f8f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/checker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ def accept_loop(
618618
self.options.enabled_error_codes.add(codes.REDUNDANT_EXPR)
619619
if warn_unreachable or warn_redundant:
620620
with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1):
621+
if on_enter_body is not None:
622+
on_enter_body()
623+
621624
self.accept(body)
622625

623626
# If exit_condition is set, assume it must be False on exit from the loop:

test-data/unit/check-inference.test

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,17 @@ foo = [
38953895
reveal_type(foo) # N: Revealed type is "builtins.list[Tuple[builtins.int, typing.Sequence[builtins.str]]]"
38963896
[builtins fixtures/tuple.pyi]
38973897

3898-
[case testForLoopIndexVaribaleNarrowing]
3898+
[case testForLoopIndexVaribaleNarrowing1]
3899+
# flags: --local-partial-types
3900+
from typing import Union
3901+
x: Union[int, str]
3902+
x = "abc"
3903+
for x in list[int]():
3904+
reveal_type(x) # N: Revealed type is "builtins.int"
3905+
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
3906+
3907+
[case testForLoopIndexVaribaleNarrowing2]
3908+
# flags: --enable-error-code=redundant-expr
38993909
from typing import Union
39003910
x: Union[int, str]
39013911
x = "abc"

0 commit comments

Comments
 (0)