(
&self,
callback: Option<PyObjectRef>,
typ: PyTypeRef,
vm: &VirtualMachine,
)
| 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, |
no test coverage detected