1+ from __future__ import annotations
2+
13import types
24from collections import defaultdict
35from dataclasses import dataclass
@@ -36,7 +38,7 @@ def __init__(
3638 ] = None ,
3739 ) -> None :
3840 # a BasicBlock object, or None
39- self .next_block : Optional [" BasicBlock" ] = None
41+ self .next_block : Optional [BasicBlock ] = None
4042 if instructions :
4143 super ().__init__ (instructions )
4244
@@ -129,7 +131,7 @@ def legalize(self, first_lineno: int) -> int:
129131
130132 return current_lineno
131133
132- def get_jump (self ) -> Optional [" BasicBlock" ]:
134+ def get_jump (self ) -> Optional [BasicBlock ]:
133135 if not self :
134136 return None
135137
@@ -243,7 +245,7 @@ def __init__(
243245 self .pending_try_begin = pending_try_begin
244246 self ._current_try_begin = pending_try_begin
245247
246- def run (self ) -> Generator [Union [" _StackSizeComputer" , int ], int , None ]:
248+ def run (self ) -> Generator [Union [_StackSizeComputer , int ], int , None ]:
247249 """Iterate over the block instructions to compute stack usage."""
248250 # Blocks are not hashable but in this particular context we know we won't be
249251 # modifying blocks in place so we can safely use their id as hash rather than
@@ -343,9 +345,11 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
343345 None ,
344346 # Do not propagate the TryBegin if a final instruction is followed
345347 # by a TryEnd.
346- None
347- if instr .is_final () and self .block .get_trailing_try_end (i )
348- else self ._current_try_begin ,
348+ (
349+ None
350+ if instr .is_final () and self .block .get_trailing_try_end (i )
351+ else self ._current_try_begin
352+ ),
349353 )
350354
351355 # Update the maximum used size by the usage implied by the following
@@ -362,8 +366,10 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
362366 # start with a TryEnd relevant only when reaching this block
363367 # through a particular jump. So we are lenient here.
364368 if (
365- te := self .block .get_trailing_try_end (i )
366- ) and te .entry is self ._current_try_begin :
369+ (te := self .block .get_trailing_try_end (i ))
370+ and self ._current_try_begin is not None
371+ and te .entry is self ._current_try_begin
372+ ):
367373 assert isinstance (te .entry .target , BasicBlock )
368374 yield from self ._compute_exception_handler_stack_usage (
369375 te .entry .target ,
@@ -426,7 +432,7 @@ def _update_size(self, pre_delta: int, post_delta: int) -> None:
426432
427433 def _compute_exception_handler_stack_usage (
428434 self , block : BasicBlock , push_lasti : bool
429- ) -> Generator [Union [" _StackSizeComputer" , int ], int , None ]:
435+ ) -> Generator [Union [_StackSizeComputer , int ], int , None ]:
430436 b_id = id (block )
431437 if self .minsize < self .common .exception_block_startsize [b_id ]:
432438 block_size = yield _StackSizeComputer (
@@ -737,7 +743,7 @@ def get_dead_blocks(self) -> List[BasicBlock]:
737743 return [b for b in self if id (b ) not in seen_block_ids ]
738744
739745 @staticmethod
740- def from_bytecode (bytecode : _bytecode .Bytecode ) -> " ControlFlowGraph" :
746+ def from_bytecode (bytecode : _bytecode .Bytecode ) -> ControlFlowGraph :
741747 # label => instruction index
742748 label_to_block_index = {}
743749 jumps = []
0 commit comments