Skip to content

Commit 123d5a4

Browse files
committed
Explain (the difference between) else_body.is_unreachable and unreachable_else.
1 parent 97275b2 commit 123d5a4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mypy/nodes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,12 @@ class IfStmt(Statement):
18291829

18301830
expr: list[Expression]
18311831
body: list[Block]
1832-
else_body: Block | None
1833-
unreachable_else: bool
1832+
else_body: Block | None # If there is actually no else statement, semantic analysis may nevertheless
1833+
# create an empty else block and mark it permanently as unreachable to tell
1834+
# that the control flow must always go through the if block.
1835+
unreachable_else: bool # Type checking may modify this flag repeatedly to indicate whether an actually
1836+
# available or unavailable else block is unreachable, considering the currently
1837+
# available type information.
18341838

18351839
def __init__(self, expr: list[Expression], body: list[Block], else_body: Block | None) -> None:
18361840
super().__init__()

0 commit comments

Comments
 (0)