From 76fa447915c8ab79a9268ca714703e50ee43fd9c Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Fri, 6 Nov 2020 11:10:53 -0600 Subject: [PATCH] Only define buffered.flush for writer/random --- vm/src/stdlib/io.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 1d9a766a3..1c75a751f 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -1384,13 +1384,6 @@ mod _io { Ok(res) } #[pymethod] - fn flush(&self, vm: &VirtualMachine) -> PyResult<()> { - let mut data = self.lock(vm)?; - let raw = data.check_init(vm)?; - ensure_unclosed(raw, "flush of closed file", vm)?; - data.flush_rewind(vm) - } - #[pymethod] fn detach(zelf: PyRef, vm: &VirtualMachine) -> PyResult { call_method(vm, zelf.as_object(), "flush", ())?; let mut data = zelf.lock(vm)?; @@ -1626,6 +1619,13 @@ mod _io { data.write(obj, vm) } + #[pymethod] + fn flush(&self, vm: &VirtualMachine) -> PyResult<()> { + let mut data = self.writer().lock(vm)?; + let raw = data.check_init(vm)?; + ensure_unclosed(raw, "flush of closed file", vm)?; + data.flush_rewind(vm) + } } #[pyattr] @@ -2949,6 +2949,14 @@ mod fileio { } } + #[pymethod] + fn flush(&self, vm: &VirtualMachine) -> PyResult<()> { + let mut handle = self.get_file(vm)?; + handle.flush().map_err(|e| e.into_pyexception(vm))?; + self.set_file(handle)?; + Ok(()) + } + #[pymethod] fn read(&self, read_byte: OptionalSize, vm: &VirtualMachine) -> PyResult> { if !self.mode.load().contains(Mode::READABLE) {