Skip to content

Commit bc02c5f

Browse files
committed
io.__del__
1 parent a20ed5d commit bc02c5f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vm/src/stdlib/io.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ fn io_base_cm_enter(instance: PyObjectRef) -> PyObjectRef {
408408
instance
409409
}
410410

411+
fn io_base_cm_del(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
412+
vm.call_method(&instance, "close", vec![])?;
413+
Ok(())
414+
}
415+
411416
fn io_base_cm_exit(instance: PyObjectRef, _args: PyFuncArgs, vm: &VirtualMachine) -> PyResult<()> {
412417
vm.call_method(&instance, "close", vec![])?;
413418
Ok(())
@@ -1269,6 +1274,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
12691274
// IOBase the abstract base class of the IO Module
12701275
let io_base = py_class!(ctx, "_IOBase", &ctx.types.object_type, {
12711276
"__enter__" => ctx.new_method(io_base_cm_enter),
1277+
"__del__" => ctx.new_method(io_base_cm_del),
12721278
"__exit__" => ctx.new_method(io_base_cm_exit),
12731279
"seekable" => ctx.new_method(io_base_seekable),
12741280
"readable" => ctx.new_method(io_base_readable),

0 commit comments

Comments
 (0)