Skip to content

codegen: preserve symbol tables across copied finally bodies - #8507

Draft
youknowone wants to merge 1 commit into
RustPython:mainfrom
youknowone:agent/finally-symbol-table-cursors
Draft

codegen: preserve symbol tables across copied finally bodies#8507
youknowone wants to merge 1 commit into
RustPython:mainfrom
youknowone:agent/finally-symbol-table-cursors

Conversation

@youknowone

Copy link
Copy Markdown
Member

Summary

  • preserve the current symbol-table cursors while codegen emits the extra copy of a finally body used by an early return, break, or continue
  • add coverage for lambdas, comprehensions, nested functions, and nested classes in copied finally bodies

Root cause

Leaving a try block early compiles its finally body once for the early-exit path and again for the statement's normal cleanup paths. The first copy consumed the nested-scope symbol-table cursors. When the later copy reached a comprehension or another nested scope, codegen reported SyntaxError: no symbol table available.

Saving and restoring all three cursor components around the early-exit copy makes that speculative emission cursor-neutral, matching the existing treatment of duplicated codegen paths.

This surfaced while importing pytest: _pytest/pytester.py has a generator hook that returns from a try and uses comprehensions in finally.

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi --all-targets
  • cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi
  • (cd crates/capi && cargo test) — 102 passed
  • CI-equivalent release build with threading,jit and the explicit stdlib/sqlite/rustls feature set
  • extra_tests: 410 passed
  • byte-compiled pytest 9.1.1's _pytest/pytester.py

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 525313ac-95ef-463d-87e2-22320efb821d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant