Title: codegen: preserve symbol tables across copied finally bodies by youknowone · Pull Request #8507 · RustPython/RustPython · GitHub
Open Graph Title: codegen: preserve symbol tables across copied finally bodies by youknowone · Pull Request #8507 · RustPython/RustPython
X Title: codegen: preserve symbol tables across copied finally bodies by youknowone · Pull Request #8507 · RustPython/RustPython
Description: 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 Summary by CodeRabbit Bug Fixes Fixed try/finally handling to preserve correct behavior after returns, breaks, and continues. Ensured finally blocks execute exactly once during returns. Corrected generator behavior when returning from try blocks, including proper StopIteration values. Preserved nested comprehension and scope behavior in duplicated finally code. Tests Added regression coverage for control flow, generators, nested scopes, and try/finally execution.
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8507
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d667d006-0a4e-e968-5d1a-b42a03d5578a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A5D4:9E1B2:2FE60C6:3F61191:6B0029BC |
| html-safe-nonce | bb136d8f1f4cf8d90207cd72c9ac0ce22094cb7e4c2b2583d45c5caf6ca52182 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUQ0OjlFMUIyOjJGRTYwQzY6M0Y2MTE5MTo2QjAwMjlCQyIsInZpc2l0b3JfaWQiOiI2MzkzOTI2ODQzMzcxNjI4OTg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 64c63021039264df8c4650eaa9af652eeeea3e2b9ae0695419ac884301d40b42 |
| hovercard-subject-tag | pull_request:4267248629 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8507/files |
| twitter:image | https://avatars.githubusercontent.com/u/69878?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/69878?s=400&v=4 |
| og:image:alt | 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 ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width