Title: Make SystemExit.code a writable attribute set at init by kangdora · Pull Request #8282 · RustPython/RustPython · GitHub
Open Graph Title: Make SystemExit.code a writable attribute set at init by kangdora · Pull Request #8282 · RustPython/RustPython
X Title: Make SystemExit.code a writable attribute set at init by kangdora · Pull Request #8282 · RustPython/RustPython
Description: Closes #8230 This PR follows our AI policy Summary SystemExit.code was a read-only getset recomputed from args on every access, so assigning or deleting exc.code raised AttributeError, and mutating exc.args after init changed code. It is now stored in a dedicated struct field (#[repr(C)] with a PyBaseException base, the same approach as OSError), set at __init__ time — writable, deletable, and independent from args after init, as in CPython. Keeping it in a field rather than the instance dict leaves SystemExit().__dict__ empty, matching CPython. A second commit updates handle_exit_exception to read the exit status from the code attribute like CPython's handle_system_exit; without it, reassigning exc.code would not affect the process exit status: import sys try: sys.exit(1) except SystemExit as e: e.code = 0 # before: AttributeError: ... not writable raise # process exit status — before: 1, after: 0 (matches CPython) Test plan Verified against CPython 3.14.6: attribute write/delete including the subclass repro from #8230, exit statuses for sys.exit() / sys.exit(3) / sys.exit('msg') / raise SystemExit(1, 2), and the re-raise case above. Lib/test/test_exceptions.py, Lib/test/test_sys.py: no regressions (the single test_badisinstance failure is pre-existing on main). test_threading / test_io thread-finalization cases pass (SystemExit is now created via the full constructor path, not new_exception). cargo fmt / cargo clippy: clean (no new warnings). Assisted-by: Claude Code:claude-fable-5 Summary by CodeRabbit Summary by CodeRabbit Bug Fixes Improved handling of SystemExit during termination, including finalization and non-main threads. Exit codes are now derived from SystemExit.code (with None mapping to 0; integer values supported). SystemExit output is generated more reliably from the code value when present. SystemExit created via exit (and internal thread exit) now follows the same raising path, ensuring consistent behavior with provided exit values.
Open Graph Description: Closes #8230 This PR follows our AI policy Summary SystemExit.code was a read-only getset recomputed from args on every access, so assigning or deleting exc.code raised AttributeError, and mutati...
X Description: Closes #8230 This PR follows our AI policy Summary SystemExit.code was a read-only getset recomputed from args on every access, so assigning or deleting exc.code raised AttributeError, and mutati...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8282
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:10878450-216d-b1d6-90f6-2152bc585fcc |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A822:969D6:1899973:21377EC:6A597BD1 |
| html-safe-nonce | e687c6e62f0f476c0c16928eb5ab7071c629e62e78e069d4c402191df0727b81 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODIyOjk2OUQ2OjE4OTk5NzM6MjEzNzdFQzo2QTU5N0JEMSIsInZpc2l0b3JfaWQiOiI3MzQ2MTE3NDA3ODAxOTY1NTIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f092ea059a23d8ee911309529bb2237a633129510242a7f5bb85b05c5d633287 |
| hovercard-subject-tag | pull_request:4048728696 |
| 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/8282/files |
| twitter:image | https://avatars.githubusercontent.com/u/182498567?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/182498567?s=400&v=4 |
| og:image:alt | Closes #8230 This PR follows our AI policy Summary SystemExit.code was a read-only getset recomputed from args on every access, so assigning or deleting exc.code raised AttributeError, and mutati... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | a540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5 |
| 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 | 624bb50a7497aa346bef8cc3743af408a9ea10ca |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width