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

Method downgrade_with_typ

crates/vm/src/object/core.rs:1352–1387  ·  view source on GitHub ↗
(
        &self,
        callback: Option<PyObjectRef>,
        typ: PyTypeRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1350 }
1351
1352 pub(crate) fn downgrade_with_typ(
1353 &self,
1354 callback: Option<PyObjectRef>,
1355 typ: PyTypeRef,
1356 vm: &VirtualMachine,
1357 ) -> PyResult<PyRef<PyWeak>> {
1358 // Check HAS_WEAKREF flag first
1359 if !self
1360 .class()
1361 .slots
1362 .flags
1363 .has_feature(crate::types::PyTypeFlags::HAS_WEAKREF)
1364 {
1365 return Err(vm.new_type_error(format!(
1366 "cannot create weak reference to '{}' object",
1367 self.class().name()
1368 )));
1369 }
1370 let dict = if typ
1371 .slots
1372 .flags
1373 .has_feature(crate::types::PyTypeFlags::HAS_DICT)
1374 {
1375 Some(vm.ctx.new_dict())
1376 } else {
1377 None
1378 };
1379 let cls_is_weakref = typ.is(vm.ctx.types.weakref_type);
1380 let wrl = self.weak_ref_list().ok_or_else(|| {
1381 vm.new_type_error(format!(
1382 "cannot create weak reference to '{}' object",
1383 self.class().name()
1384 ))
1385 })?;
1386 Ok(wrl.add(self, typ, cls_is_weakref, callback, dict))
1387 }
1388
1389 pub fn downgrade(
1390 &self,

Callers 3

slot_newMethod · 0.80
py_newMethod · 0.80
downgradeMethod · 0.80

Calls 9

has_featureMethod · 0.80
new_dictMethod · 0.80
isMethod · 0.80
ok_or_elseMethod · 0.80
weak_ref_listMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
classMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected