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

Method del

crates/stdlib/src/socket.rs:1421–1451  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1419
1420 impl Destructor for PySocket {
1421 fn del(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
1422 // Emit ResourceWarning if socket is still open
1423 if zelf.sock.read().is_some() {
1424 let laddr = if let Ok(sock) = zelf.sock()
1425 && let Ok(addr) = sock.local_addr()
1426 && let Ok(repr) = get_addr_tuple(&addr, vm).repr(vm)
1427 {
1428 format!(", laddr={}", repr.as_wtf8())
1429 } else {
1430 String::new()
1431 };
1432
1433 let msg = format!(
1434 "unclosed <socket.socket fd={}, family={}, type={}, proto={}{}>",
1435 zelf.fileno(),
1436 zelf.family.load(),
1437 zelf.kind.load(),
1438 zelf.proto.load(),
1439 laddr
1440 );
1441 let _ = crate::vm::warn::warn(
1442 vm.ctx.new_str(msg).into(),
1443 Some(vm.ctx.exceptions.resource_warning.to_owned()),
1444 1,
1445 None,
1446 vm,
1447 );
1448 }
1449 let _ = zelf.close();
1450 Ok(())
1451 }
1452 }
1453
1454 #[pyclass(

Callers

nothing calls this directly

Calls 10

get_addr_tupleFunction · 0.85
newFunction · 0.85
sockMethod · 0.80
warnFunction · 0.50
SomeClass · 0.50
readMethod · 0.45
reprMethod · 0.45
new_strMethod · 0.45
to_ownedMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected