8000 add IMMUTABLE flag and set non-heaptype as immutable by lijm1358 · Pull Request #3821 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

add IMMUTABLE flag and set non-heaptype as immutable #3821

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
12 changes: 12 additions & 0 deletions vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ impl PyType {
}
}

if !slots.flags.has_feature(PyTypeFlags::HEAPTYPE) {
slots.flags |= PyTypeFlags::IMMUTABLETYPE
}

let new_type = PyRef::new_ref(
PyType {
base: Some(base),
Expand Down Expand Up @@ -1339,6 +1343,14 @@ impl SetAttr for PyType {
value: PySetterValue,
vm: &VirtualMachine,
) -> PyResult<()> {
if zelf.slots.flags.has_feature(PyTypeFlags::IMMUTABLETYPE) {
return Err(vm.new_type_error(format!(
"cannot set '{}' attribute of immutable type '{}'",
attr_name,
zelf.name()
)));
}

// TODO: pass PyRefExact instead of &str
let attr_name = vm.ctx.intern_str(attr_name.as_str());
if let Some(attr) = zelf.get_class_attr(attr_name) {
Expand Down
Loading
0