sys._clear_type_descriptors (#6795)

This commit is contained in:
Jeong, YunWon authored and GitHub committed 2026-01-19 16:43:20 +09:00
1 parent 6a064aad3b
commit d7a885cea8
2 files changed
+27

No files matched your search

+26
View File
@@ -1215,6 +1215,32 @@ mod sys {
crate::vm::thread::COROUTINE_ORIGIN_TRACKING_DEPTH.get() as i32
}
#[pyfunction]
fn _clear_type_descriptors(type_obj: PyTypeRef, vm: &VirtualMachine) -> PyResult<()> {
use crate::types::PyTypeFlags;
// Check if type is immutable
if type_obj.slots.flags.has_feature(PyTypeFlags::IMMUTABLETYPE) {
return Err(vm.new_type_error("argument is immutable".to_owned()));
}
let mut attributes = type_obj.attributes.write();
// Remove __dict__ descriptor if present
attributes.swap_remove(identifier!(vm, __dict__));
// Remove __weakref__ descriptor if present
attributes.swap_remove(identifier!(vm, __weakref__));
drop(attributes);
// Update slots to notify subclasses and recalculate cached values
type_obj.update_slot::<true>(identifier!(vm, __dict__), &vm.ctx);
type_obj.update_slot::<true>(identifier!(vm, __weakref__), &vm.ctx);
Ok(())
}
#[pyfunction]
fn getswitchinterval(vm: &VirtualMachine) -> f64 {
// Return the stored switch interval
+1
View File
@@ -234,6 +234,7 @@ declare_const_name! {
__typing_is_unpacked_typevartuple__,
__typing_prepare_subst__,
__typing_unpacked_tuple_args__,
__weakref__,
__xor__,
// common names