◐ Shell
clean mode source ↗

GH-96793: Implement PEP 479 in bytecode. by markshannon · Pull Request #99006 · python/cpython

In order to specialize iteration over generators and send to coroutines we need to remove the pre- and post checks from the C wrappers.
The pre-checks are largely eliminated by the the compiler and specialization.
The post-checks need to be handled in bytecode.
To do that, we wrap the generator body in a try: ... except StopIteration: ... which converts the StopIteration into a RuntimeError.

I initially did this entirely in bytecode, but it adds a lot of bulk to the bytecode.

The new STOPITERATION_ERROR instruction should only be temporary: #99005