Skip to content

Commit f0378fe

Browse files
Fix mypy type narrowing false positive in cfg.py (#190)
* Initial plan * Fix mypy type narrowing error in cfg.py by adding None check before identity comparison Agent-Logs-Url: https://github.com/MatthieuDartiailh/bytecode/sessions/b7904bd0-bbc8-412f-8f14-de2ed29696a1 Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com> * Fix black formatting in cfg.py Agent-Logs-Url: https://github.com/MatthieuDartiailh/bytecode/sessions/8ed3b0c7-8cc3-4d4c-9421-7a291774fbd9 Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com> Co-authored-by: Matthieu Dartiailh <m.dartiailh@gmail.com>
1 parent 1757c49 commit f0378fe

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/bytecode/cfg.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,11 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
343343
None,
344344
# Do not propagate the TryBegin if a final instruction is followed
345345
# by a TryEnd.
346-
None
347-
if instr.is_final() and self.block.get_trailing_try_end(i)
348-
else self._current_try_begin,
346+
(
347+
None
348+
if instr.is_final() and self.block.get_trailing_try_end(i)
349+
else self._current_try_begin
350+
),
349351
)
350352

351353
# Update the maximum used size by the usage implied by the following
@@ -362,8 +364,10 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
362364
# start with a TryEnd relevant only when reaching this block
363365
# through a particular jump. So we are lenient here.
364366
if (
365-
te := self.block.get_trailing_try_end(i)
366-
) and te.entry is self._current_try_begin:
367+
(te := self.block.get_trailing_try_end(i))
368+
and self._current_try_begin is not None
369+
and te.entry is self._current_try_begin
370+
):
367371
assert isinstance(te.entry.target, BasicBlock)
368372
yield from self._compute_exception_handler_stack_usage(
369373
te.entry.target,

0 commit comments

Comments
 (0)