mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
fix(socket): use object repr in deallocation warnings (#8422)
Assisted-by: Codex:gpt-5.6-sol
This commit is contained in:
1 parent
9e92f96929
commit
aa4f98a765
2 files changed
+5
-18
No files matched your search
Vendored
-1
@@ -754,7 +754,6 @@ class BasicSocketTests(unittest.TestCase):
|
||||
with test_wrap_socket(s, server_side=True, certfile=CERTFILE) as ss:
|
||||
self.assertIsNone(ss.get_channel_binding("tls-unique"))
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: "<ssl.SSLSocket fd=3, family=2, type=1, proto=0, laddr=('0.0.0.0', 0)>" not found in "unclosed <socket.socket fd=3, family=2, type=1, proto=0, laddr=('0.0.0.0', 0)>"
|
||||
def test_dealloc_warn(self):
|
||||
ss = test_wrap_socket(socket.socket(socket.AF_INET))
|
||||
r = repr(ss)
|
||||
|
||||
@@ -1378,23 +1378,11 @@ mod _socket {
|
||||
fn del(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
|
||||
// Emit ResourceWarning if socket is still open
|
||||
if zelf.sock.read().is_some() {
|
||||
let laddr = if let Ok(sock) = zelf.sock()
|
||||
&& let Ok(addr) = sock.local_addr()
|
||||
&& let Ok(repr) = get_addr_tuple(&addr, vm).repr(vm)
|
||||
{
|
||||
format!(", laddr={}", repr.as_wtf8())
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let msg = format!(
|
||||
"unclosed <socket.socket fd={}, family={}, type={}, proto={}{}>",
|
||||
zelf.fileno(),
|
||||
zelf.family.load(),
|
||||
zelf.kind.load(),
|
||||
zelf.proto.load(),
|
||||
laddr
|
||||
);
|
||||
let repr = zelf
|
||||
.as_object()
|
||||
.repr(vm)
|
||||
.unwrap_or_else(|_| vm.ctx.new_str("<socket>"));
|
||||
let msg = format!("unclosed {}", repr.as_wtf8());
|
||||
let _ = crate::vm::warn::warn(
|
||||
vm.ctx.new_str(msg).into(),
|
||||
Some(vm.ctx.exceptions.resource_warning.to_owned()),
|
||||
|
||||
Reference in new issue
Block a user