Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix block graph for generators and comprehensions in 3.12
3.11 uses exceptions to break out of `async for` loops. Pytype doesn't represent those exceptions. See `_add_setup_except` opcodes.py, where pytype skips adding exception blocks for anything but proper `try..except/finally` statements. This means pytype would never reach the end of an `async for` loop, because it doesn't see any jumps leading there. The solution is to remove the `JUMP_BACKWARD` code preceding `END_ASYNC_FOR`. This way `async for` loops just end after the first round. 3.12 uses the same pattern for generators and comprehensions: - generators: Now `YIELD_VALUE` can jump to `CLEANUP_THROW`, which is preceded by a `JUMP_BACKWARD`. The solution again is to remove the `JUMP_BACKWARD`. And since `CLEANUP_THROW` doesn't do anything useful (its sole purpose is handling of a StopIteration exception), we can remove it as well. - comprehensions: List/dict/set comprehensions are now inlined (they were compiled into separate functions before). In case anything throws during the comprehension logic, it jumps to a set of opcodes (starting with `SWAP`) to clean up the stack before re-raising the exception. This exception handling doesn't affect type information and therefore pytype may skip it. Failing tests: before=207, after=157 PiperOrigin-RevId: 655569260
- Loading branch information