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

Method py_new

crates/vm/src/builtins/weakproxy.rs:40–59  ·  view source on GitHub ↗
(
        _cls: &Py<PyType>,
        Self::Args { referent, callback }: Self::Args,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

38 type Args = WeakProxyNewArgs;
39
40 fn py_new(
41 _cls: &Py<PyType>,
42 Self::Args { referent, callback }: Self::Args,
43 vm: &VirtualMachine,
44 ) -> PyResult<Self> {
45 // using an internal subclass as the class prevents us from getting the generic weakref,
46 // which would mess up the weakref count
47 let weak_cls = WEAK_SUBCLASS.get_or_init(|| {
48 vm.ctx.new_class(
49 None,
50 "__weakproxy",
51 vm.ctx.types.weakref_type.to_owned(),
52 super::PyWeak::make_slots(),
53 )
54 });
55 // TODO: PyWeakProxy should use the same payload as PyWeak
56 Ok(Self {
57 weak: referent.downgrade_with_typ(callback.into_option(), weak_cls.clone(), vm)?,
58 })
59 }
60}
61
62crate::common::static_cell! {

Callers

nothing calls this directly

Calls 6

new_classMethod · 0.80
downgrade_with_typMethod · 0.80
into_optionMethod · 0.80
get_or_initMethod · 0.45
to_ownedMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected