{{ message }}
Make SystemExit.code a writable attribute set at init - #8282
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/vm/src/exceptions.rs (1)
1658-1676: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMove the
BaseException_initnote to thePyBaseException::slot_initcall below. The current placement describes the match above, not the call it refers to.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/vm/src/exceptions.rs` around lines 1658 - 1676, Move the “Call BaseException_init first (handles args)” comment from above the code match in PySystemExit::slot_init to immediately above the PyBaseException::slot_init call, so it documents the call it refers to.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/vm/src/exceptions.rs`:
- Around line 1658-1676: Move the “Call BaseException_init first (handles args)”
comment from above the code match in PySystemExit::slot_init to immediately
above the PyBaseException::slot_init call, so it documents the call it refers
to.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 6a9aa971-2421-42b9-9cad-54153f7ebee2
📒 Files selected for processing (1)
crates/vm/src/exceptions.rs
youknowone
approved these changes
Jul 15, 2026
youknowone
left a comment
Member
There was a problem hiding this comment.
looks great, thanks! welcome to RustPython project!
note about the change: once we couldn't set getset to exception subtypes. that restriction was resolved early this year, but this one was not updated for a while.
This was referenced Jul 16, 2026
2 tasks
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
SystemExit.codewas a read-only getset recomputed fromargsonevery access, so assigning or deleting
exc.coderaisedAttributeError, and mutatingexc.argsafter init changedcode.It is now stored in a dedicated struct field (
#[repr(C)]with aPyBaseExceptionbase, the same approach asOSError), set at__init__time — writable, deletable, and independent fromargsafter 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_exceptionto read the exitstatus from the
codeattribute like CPython'shandle_system_exit;without it, reassigning
exc.codewould not affect the process exitstatus:
Test plan
sys.exit(3) / sys.exit('msg') / raise SystemExit(1, 2), and the re-raise case above.
now created via the full constructor path, not new_exception).
Assisted-by: Claude Code:claude-fable-5
Summary by CodeRabbit
Summary by CodeRabbit
SystemExitduring termination, including finalization and non-main threads.SystemExit.code(withNonemapping to0; integer values supported).SystemExitoutput is generated more reliably from thecodevalue when present.SystemExitcreated viaexit(and internal thread exit) now follows the same raising path, ensuring consistent behavior with provided exit values.