Skip to content

Commit cd59649

Browse files
committed
Workaround MyPy's awful flow analysis.
1 parent 907d768 commit cd59649

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Tools/cases_generator/generators_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def _emit_stmt(
470470
method = getattr(self, method_name, None)
471471
if method is None:
472472
raise NotImplementedError
473-
return method(stmt, uop, storage, inst) # type: ignore
473+
return method(stmt, uop, storage, inst) # type: ignore[no-any-return]
474474

475475
def emit_SimpleStmt(
476476
self,
@@ -569,8 +569,8 @@ def emit_IfStmt(
569569
for tkn in stmt.condition:
570570
self.out.emit(tkn)
571571
if_storage = storage.copy()
572+
rbrace: Token | None = stmt.if_
572573
try:
573-
rbrace: Token | None = stmt.if_
574574
reachable, rbrace, if_storage = self._emit_stmt(stmt.body, uop, if_storage, inst)
575575
if stmt.else_ is not None:
576576
assert rbrace is not None
@@ -609,6 +609,7 @@ def emit_BlockStmt(
609609
emit_braces: bool = True,
610610
) -> tuple[bool, Token | None, Storage]:
611611
""" Returns (reachable?, closing '}', stack)."""
612+
tkn: Token | None = None
612613
try:
613614
if emit_braces:
614615
self.out.emit(stmt.open)

Tools/cases_generator/parsing.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,15 @@ def label_def(self) -> LabelDef | None:
361361
@contextual
362362
def inst_def(self) -> InstDef | None:
363363
if hdr := self.inst_header():
364-
if block := self.block():
365-
return InstDef(
366-
hdr.annotations,
367-
hdr.kind,
368-
hdr.name,
369-
hdr.inputs,
370-
hdr.outputs,
371-
block,
372-
)
373-
raise self.make_syntax_error("Expected block")
364+
block := self.block()
365+
return InstDef(
366+
hdr.annotations,
367+
hdr.kind,
368+
hdr.name,
369+
hdr.inputs,
370+
hdr.outputs,
371+
block,
372+
)
374373
return None
375374

376375
@contextual

0 commit comments

Comments
 (0)