Skip to content

Commit 8c0f2d9

Browse files
committed
Drop for FileIO
1 parent ae6b35e commit 8c0f2d9

File tree

1 file changed

+16
-3
lines changed
  • crates/vm/src/stdlib

1 file changed

+16
-3
lines changed

crates/vm/src/stdlib/io.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,14 +4167,15 @@ mod _io {
41674167
mod fileio {
41684168
use super::{_io::*, Offset};
41694169
use crate::{
4170-
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
4170+
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
4171+
VirtualMachine,
41714172
builtins::{PyBaseExceptionRef, PyUtf8Str, PyUtf8StrRef},
41724173
common::crt_fd,
41734174
convert::{IntoPyException, ToPyException},
41744175
function::{ArgBytesLike, ArgMemoryBuffer, OptionalArg, OptionalOption},
41754176
ospath::{IOErrorBuilder, OsPath, OsPathOrFd},
41764177
stdlib::os,
4177-
types::{Constructor, DefaultConstructor, Initializer, Representable},
4178+
types::{Constructor, DefaultConstructor, Destructor, Initializer, Representable},
41784179
};
41794180
use crossbeam_utils::atomic::AtomicCell;
41804181
use std::io::{Read, Write};
@@ -4434,7 +4435,7 @@ mod fileio {
44344435
}
44354436

44364437
#[pyclass(
4437-
with(Constructor, Initializer, Representable),
4438+
with(Constructor, Initializer, Representable, Destructor),
44384439
flags(BASETYPE, HAS_DICT)
44394440
)]
44404441
impl FileIO {
@@ -4650,4 +4651,16 @@ mod fileio {
46504651
Err(vm.new_type_error(format!("cannot pickle '{}' object", zelf.class().name())))
46514652
}
46524653
}
4654+
4655+
impl Destructor for FileIO {
4656+
fn slot_del(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
4657+
let _ = vm.call_method(zelf, "close", ());
4658+
Ok(())
4659+
}
4660+
4661+
#[cold]
4662+
fn del(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<()> {
4663+
unreachable!("slot_del is implemented")
4664+
}
4665+
}
46534666
}

0 commit comments

Comments
 (0)