-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Properly handles del val.__dict__.
#5576
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
Open
hbina
wants to merge
6
commits into
RustPython:main
Choose a base branch
from
hbina:hbina-fix-issue-5355
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+45
−11
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2010890
Implemented the ability to del __dict__
hbina 1abd204
Implement delete object dictionary
key262yek c43327e
Refactor object dictionary setter to handle delete and assign operations
key262yek 79d70e3
Enhance object dictionary handling in type and object modules
key262yek 02ce85a
Implemented the ability to del __dict__
hbina 425fd4f
Update vm/src/object/core.rs
hbina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor object dictionary setter to handle delete and assign operations
- Simplify object_set_dict method in object.rs - Update set_dict method in core.rs to handle both assignment and deletion - Consolidate dictionary modification logic
- Loading branch information
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -712,49 +712,21 @@ impl PyObject { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Set the dict field. Returns `Err(dict)` if this object does not have a dict field | ||||||||||||||||||||||
| /// in the first place. | ||||||||||||||||||||||
| pub fn set_dict(&self, dict: PySetterValue<PyDictRef>) -> Option<()> { | ||||||||||||||||||||||
| // NOTE(hanif) - So far, this is the only error condition that I know of so we can use Option | ||||||||||||||||||||||
| // for now. | ||||||||||||||||||||||
| if self.payload_is::<crate::builtins::function::PyFunction>() { | ||||||||||||||||||||||
| return None; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| pub fn set_dict(&self, dict: PySetterValue<PyDictRef>) -> Result<(), PyDictRef> { | ||||||||||||||||||||||
| match (self.instance_dict(), dict) { | ||||||||||||||||||||||
| (Some(d), PySetterValue::Assign(dict)) => { | ||||||||||||||||||||||
| d.set(dict); | ||||||||||||||||||||||
| Ok(()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| (None, PySetterValue::Assign(dict)) => { | ||||||||||||||||||||||
| // self.0.dict = Some(InstanceDict::new(dict)); | ||||||||||||||||||||||
| unsafe { | ||||||||||||||||||||||
| let ptr = self as *const _ as *mut PyObject; | ||||||||||||||||||||||
| (*ptr).0.dict = Some(InstanceDict::new(dict)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| (None, PySetterValue::Assign(dict)) => Err(dict), | ||||||||||||||||||||||
| (Some(_), PySetterValue::Delete) => { | ||||||||||||||||||||||
| // self.0.dict = None; | ||||||||||||||||||||||
| unsafe { | ||||||||||||||||||||||
| let ptr = self as *const _ as *mut PyObject; | ||||||||||||||||||||||
| (*ptr).0.dict = None; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| (None, PySetterValue::Delete) => { | ||||||||||||||||||||||
| // NOTE(hanif) - noop? | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Some(()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| pub fn delete_dict(&self) -> Result<(), ()> { | ||||||||||||||||||||||
| match self.instance_dict() { | ||||||||||||||||||||||
| Some(_) => { | ||||||||||||||||||||||
| unsafe { | ||||||||||||||||||||||
| let ptr = self as *const _ as *mut PyObject; | ||||||||||||||||||||||
| (*ptr).0.dict = None; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Ok(()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+733
to
+739
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't do this because it only have |
||||||||||||||||||||||
| None => Err(()), | ||||||||||||||||||||||
| (None, PySetterValue::Delete) => Ok(()), | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
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.
The doc-comment doesn't fit in actual implementation anymore