Merged
Conversation
2d070d3 to
53c6dcb
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR makes a minor revision for issue #22 by adding a new test to verify Python object conversions and enhancing the deserialization logic.
- Added a new test (check_python_object) in tests/check_revertible.rs to validate Python and Rust object parity.
- Updated the deserialization logic in src/de.rs by handling objects with dict and slots.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/check_revertible.rs | Added a new test to verify proper conversion between Python and Rust objects. |
| src/de.rs | Enhanced deserialization to support dict and slots attributes in Python. |
Comment on lines
+139
to
+149
| #[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
| struct MyClass { | ||
| name: String, | ||
| age: i32, | ||
| } | ||
|
|
||
| Python::with_gil(|py| { | ||
| // Create an instance of Python object | ||
| py.run( | ||
| c_str!( | ||
| r#" |
There was a problem hiding this comment.
[nitpick] The MyClass definition is redefined within this test. Consider extracting it to a shared test module if it's used in multiple tests to avoid duplication.
Suggested change
| #[derive(Debug, PartialEq, Serialize, Deserialize)] | |
| struct MyClass { | |
| name: String, | |
| age: i32, | |
| } | |
| Python::with_gil(|py| { | |
| // Create an instance of Python object | |
| py.run( | |
| c_str!( | |
| r#" | |
| #[derive(Debug, PartialEq, Serialize, Deserialize)] | |
| struct MyClass { | |
| name: String, | |
| age: i32, | |
| } |
| for key in obj.getattr("__slots__")?.try_iter()? { | ||
| let key = key?; | ||
| keys.push(key.clone()); | ||
| let v = obj.getattr(key.str()?)?; |
There was a problem hiding this comment.
[nitpick] Consider providing additional context in error handling for key conversion (i.e., key.str()?) to account for unexpected non-string slot names, improving overall robustness.
Suggested change
| let v = obj.getattr(key.str()?)?; | |
| let key_str = key.str().map_err(|e| { | |
| Error::custom(format!( | |
| "Failed to convert slot name to string: {:?}, error: {}", | |
| key, e | |
| )) | |
| })?; | |
| let v = obj.getattr(key_str)?; |
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.
No description provided.