Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update vm/src/object/core.rs
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
  • Loading branch information
hbina and youknowone committed Mar 23, 2025
commit 425fd4f673f888272be2707c308794111ce0f45e
2 changes: 1 addition & 1 deletion vm/src/object/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl PyObject {
/// Set the dict field. Returns `Err(dict)` if this object does not have a dict field
Copy link
Copy Markdown
Member

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

/// 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
// NOTE: 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>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry. I don't get how PyFunction specifically requires to be checked yet. Is this same in CPython?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because deleting dict of a function is not allowed.
I can't find the equivalent check inside of cpython...

class A:
    pass


def ff():
    return 0


# Deleting __dict__ of class is fine
a = A()
print(a.__dict__)
del a.__dict__

# Deleting __dict__ of function is not allowed
print(ff.__dict__)
del ff.__dict__

Yields

hbina085@akarin-thinkpad ~/g/RustPython (hbina-fix-issue-5355) [1]> python ggg_issue_5355.py                                                                                                                      (numbadev) 
{}
{}
Traceback (most recent call last):
  File "/home/hbina085/git/RustPython/ggg_issue_5355.py", line 16, in <module>
    del ff.__dict__
        ^^^^^^^^^^^
TypeError: cannot delete __dict__

Perhaps I should have added comments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of PyFunction, isn't it a similar, but different rule? e.g. static types, immutable types etc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instant_dict() can be simple None for those types.

return None;
Expand Down
Loading