-
Notifications
You must be signed in to change notification settings - Fork 1.3k
BaseException.__setstate__ #5821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update revises comments in several Python test files to clarify the status of RustPython features and support, particularly regarding garbage collection and Unicode handling. Additionally, a new Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ExceptionObj as PyBaseException
participant VM
Caller->>ExceptionObj: setstate(state, vm)
alt state is not None
ExceptionObj->>VM: Downcast state to dict
alt Downcast fails
VM-->>Caller: Raise TypeError
else Downcast succeeds
loop For each key-value in dict
ExceptionObj->>ExceptionObj: Set attribute key to value
end
ExceptionObj-->>Caller: Return None
end
else state is None
ExceptionObj-->>Caller: Return None
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (10)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
vm/src/exceptions.rs (1)
651-664
: LGTM: Clean implementation of__setstate__
methodThe implementation correctly follows Python's
__setstate__
pattern for exception objects. The error handling for None state and non-dictionary types is appropriate.However, consider adding validation for attribute names to prevent potential issues:
- Setting reserved/special attributes could break exception functionality
- Invalid Python identifiers as attribute names could cause issues
Consider adding basic attribute name validation:
for (key, value) in &dict { let key_str = key.str(vm)?; + // Optional: Validate attribute name + if key_str.as_str().starts_with("__") && key_str.as_str().ends_with("__") { + // Consider whether to allow setting dunder attributes + } self.as_object().set_attr(&key_str, value.clone(), vm)?; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Lib/test/support/__init__.py
(1 hunks)Lib/test/test_array.py
(1 hunks)Lib/test/test_baseexception.py
(1 hunks)vm/src/exceptions.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
🔇 Additional comments (4)
Lib/test/test_array.py (1)
179-179
: LGTM: Improved documentation clarity.The refined comment provides specific details about what functionality is needed for this test to pass, making it easier for future developers to understand the requirements for implementing UTF-32 support in RustPython.
Lib/test/support/__init__.py (1)
936-936
: LGTM: Improved documentation clarity.The updated comment provides more specific information about why the function is disabled, clearly stating that GC (garbage collection) is not supported yet in RustPython. This is more informative than the previous "comment out before" message.
Lib/test/test_baseexception.py (2)
86-86
: Comment update aligns with current statusThe change from "TODO" to "XXX" appropriately reflects that
IncompleteInputError
is a known item for future Python versions rather than an active development task.
124-147
: Test activation indicates working__setstate__
implementationThe removal of
@unittest.expectedFailure
(mentioned in AI summary) aligns perfectly with the newsetstate
method implementation invm/src/exceptions.rs
. This test validates a critical edge case where garbage collection could cause crashes during attribute setting.The test design is robust - it creates a scenario where:
- A custom hash function clears the dictionary during attribute setting
- Reference counting could drop below zero without proper handling
- Garbage collection would crash if references aren't managed correctly
Verify that this test now passes consistently with the new implementation:
#!/bin/bash # Run the specific test to confirm it passes python -m pytest Lib/test/test_baseexception.py::ExceptionClassTests::test_setstate_refcount_no_crash -v
Summary by CodeRabbit
New Features
Documentation
Refactor