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

Method clone_property_with

crates/vm/src/builtins/property.rs:191–232  ·  view source on GitHub ↗

Helper method to create a new property with updated attributes

(
        zelf: PyRef<Self>,
        new_getter: Option<PyObjectRef>,
        new_setter: Option<PyObjectRef>,
        new_deleter: Option<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

189
190 // Helper method to create a new property with updated attributes
191 fn clone_property_with(
192 zelf: PyRef<Self>,
193 new_getter: Option<PyObjectRef>,
194 new_setter: Option<PyObjectRef>,
195 new_deleter: Option<PyObjectRef>,
196 vm: &VirtualMachine,
197 ) -> PyResult<PyRef<Self>> {
198 // Determine doc based on getter_doc flag and whether we're updating the getter
199 let doc = if zelf.getter_doc.load(Ordering::Relaxed) && new_getter.is_some() {
200 // If the original property uses getter doc and we have a new getter,
201 // pass Py_None to let __init__ get the doc from the new getter
202 Some(vm.ctx.none())
203 } else if zelf.getter_doc.load(Ordering::Relaxed) {
204 // If original used getter_doc but we're not changing the getter,
205 // pass None to let init get doc from existing getter
206 Some(vm.ctx.none())
207 } else {
208 // Otherwise use the existing doc
209 zelf.doc_getter()
210 };
211
212 // Create property args with updated values
213 let args = PropertyArgs {
214 fget: new_getter.or_else(|| zelf.fget()),
215 fset: new_setter.or_else(|| zelf.fset()),
216 fdel: new_deleter.or_else(|| zelf.fdel()),
217 doc,
218 name: None,
219 };
220
221 // Create new property using py_new and init
222 let new_prop = Self::slot_new(zelf.class().to_owned(), FuncArgs::default(), vm)?;
223 let new_prop_ref = new_prop.downcast::<Self>().unwrap();
224 Self::init(new_prop_ref.clone(), args, vm)?;
225
226 // Copy the name if it exists
227 if let Some(name) = zelf.name.read().clone() {
228 *new_prop_ref.name.write() = Some(name);
229 }
230
231 Ok(new_prop_ref)
232 }
233
234 #[pymethod]
235 fn getter(

Callers

nothing calls this directly

Calls 14

noneMethod · 0.80
doc_getterMethod · 0.80
fgetMethod · 0.80
fsetMethod · 0.80
fdelMethod · 0.80
initFunction · 0.70
SomeClass · 0.50
loadMethod · 0.45
to_ownedMethod · 0.45
classMethod · 0.45
unwrapMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected