MCPcopy Index your code
hub / github.com/python/mypy / gen_condition

Method gen_condition

mypyc/irbuild/for_helpers.py:813–846  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

811 self.stop_reg = Register(bool_rprimitive)
812
813 def gen_condition(self) -> None:
814 # This does the test and fetches the next value
815 # try:
816 # TARGET = await type(iter).__anext__(iter)
817 # stop = False
818 # except StopAsyncIteration:
819 # stop = True
820 #
821 # What a pain.
822 # There are optimizations available here if we punch through some abstractions.
823
824 from mypyc.irbuild.statement import emit_await, transform_try_except
825
826 builder = self.builder
827 line = self.line
828
829 def except_match() -> Value:
830 return builder.add(
831 LoadGlobal(stop_async_iteration_op.type, stop_async_iteration_op.src, line)
832 )
833
834 def try_body() -> None:
835 awaitable = builder.call_c(anext_op, [builder.read(self.iter_target, line)], line)
836 self.next_reg = emit_await(builder, awaitable, line)
837 builder.assign(self.stop_reg, builder.false(), line)
838
839 def except_body() -> None:
840 builder.assign(self.stop_reg, builder.true(), line)
841
842 transform_try_except(
843 builder, try_body, [((except_match, line), None, except_body)], None, line
844 )
845
846 builder.add(Branch(self.stop_reg, self.loop_exit, self.body_block, Branch.BOOL))
847
848 def begin_body(self) -> None:
849 # Assign the value obtained from await __anext__ to the

Callers

nothing calls this directly

Calls 3

transform_try_exceptFunction · 0.90
BranchClass · 0.90
addMethod · 0.45

Tested by

no test coverage detected