MCPcopy Index your code
hub / github.com/RustPython/RustPython / add_to_weak_set

Function add_to_weak_set

crates/vm/src/stdlib/_abc.rs:115–135  ·  view source on GitHub ↗

Add obj to the weak set

(
        set_lock: &PyRwLock<Option<PyRef<PySet>>>,
        obj: &PyObject,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

113
114 /// Add obj to the weak set
115 fn add_to_weak_set(
116 set_lock: &PyRwLock<Option<PyRef<PySet>>>,
117 obj: &PyObject,
118 vm: &VirtualMachine,
119 ) -> PyResult<()> {
120 let mut set_opt = set_lock.write();
121 let set = match &*set_opt {
122 Some(s) => s.clone(),
123 None => {
124 let new_set = PySet::default().into_ref(&vm.ctx);
125 *set_opt = Some(new_set.clone());
126 new_set
127 }
128 };
129 drop(set_opt);
130
131 // Create a weak reference to the object
132 let weak_ref = obj.downgrade(None, vm)?;
133 set.add(weak_ref.into(), vm)?;
134 Ok(())
135 }
136
137 /// Returns the current ABC cache token.
138 #[pyfunction]

Callers 3

_abc_registerFunction · 0.85
_abc_subclasscheckFunction · 0.85

Calls 6

SomeClass · 0.50
writeMethod · 0.45
cloneMethod · 0.45
into_refMethod · 0.45
downgradeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected