Skip to content

Commit 05c183f

Browse files
committed
Implement _io.TextIOWrapper.detach method
1 parent 4a2edf9 commit 05c183f

File tree

1 file changed

+10
-4
lines changed
  • crates/vm/src/stdlib

1 file changed

+10
-4
lines changed

crates/vm/src/stdlib/io.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ mod _io {
119119
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
120120
TryFromBorrowedObject, TryFromObject,
121121
builtins::{
122-
PyBaseExceptionRef, PyByteArray, PyBytes, PyBytesRef, PyIntRef, PyMemoryView, PyStr,
123-
PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, PyUtf8StrRef,
122+
PyBaseExceptionRef, PyByteArray, PyBytes, PyBytesRef, PyIntRef, PyMemoryView, PyNone,
123+
PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, PyUtf8StrRef,
124124
},
125125
class::StaticType,
126126
common::lock::{
@@ -2440,8 +2440,14 @@ mod _io {
24402440
}
24412441

24422442
#[pymethod]
2443-
fn detach(_zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyResult {
2444-
todo!()
2443+
fn detach(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
2444+
let mut textio = zelf.lock(vm)?;
2445+
// TODO: implement CHECK_ATTACHED
2446+
// textio.check_attached(vm)?;
2447+
vm.call_method(zelf.as_object(), "flush", ())?;
2448+
let buffer = textio.buffer.clone();
2449+
textio.buffer = vm.new_pyobj(PyNone);
2450+
Ok(buffer)
24452451
}
24462452

24472453
#[pymethod]

0 commit comments

Comments
 (0)