Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy/treetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ def visit_nonlocal_decl(self, node: NonlocalDecl) -> NonlocalDecl:
return NonlocalDecl(node.names.copy())

def visit_block(self, node: Block) -> Block:
return Block(self.statements(node.body))
new = Block(self.statements(node.body))
new.is_unreachable = node.is_unreachable
return new

def visit_decorator(self, node: Decorator) -> Decorator:
# Note that a Decorator must be transformed to a Decorator.
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,16 @@ class Test4(Generic[T3]):

[builtins fixtures/isinstancelist.pyi]

[case testUnreachableBlockStaysUnreachableWithTypeVarConstraints]
# flags: --always-false COMPILE_TIME_FALSE
from typing import TypeVar
COMPILE_TIME_FALSE = False
T = TypeVar("T", int, str)
def foo(x: T) -> T:
if COMPILE_TIME_FALSE:
return "bad"
return x

[case testUnreachableFlagContextManagersNoSuppress]
# flags: --warn-unreachable
from contextlib import contextmanager
Expand Down