Skip to content

Commit f2b8e12

Browse files
committed
Add is_unreachable to Block.__init__
1 parent efa9481 commit f2b8e12

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

mypy/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,15 +1263,15 @@ class Block(Statement):
12631263

12641264
__match_args__ = ("body", "is_unreachable")
12651265

1266-
def __init__(self, body: list[Statement]) -> None:
1266+
def __init__(self, body: list[Statement], *, is_unreachable: bool = False) -> None:
12671267
super().__init__()
12681268
self.body = body
12691269
# True if we can determine that this block is not executed during semantic
12701270
# analysis. For example, this applies to blocks that are protected by
12711271
# something like "if PY3:" when using Python 2. However, some code is
12721272
# only considered unreachable during type checking and this is not true
12731273
# in those cases.
1274-
self.is_unreachable = False
1274+
self.is_unreachable = is_unreachable
12751275

12761276
def accept(self, visitor: StatementVisitor[T]) -> T:
12771277
return visitor.visit_block(self)

mypy/treetransform.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ def visit_nonlocal_decl(self, node: NonlocalDecl) -> NonlocalDecl:
276276
return NonlocalDecl(node.names.copy())
277277

278278
def visit_block(self, node: Block) -> Block:
279-
new = Block(self.statements(node.body))
280-
new.is_unreachable = node.is_unreachable
281-
return new
279+
return Block(self.statements(node.body), is_unreachable=node.is_unreachable)
282280

283281
def visit_decorator(self, node: Decorator) -> Decorator:
284282
# Note that a Decorator must be transformed to a Decorator.

0 commit comments

Comments
 (0)