Skip to content

Commit

Permalink
refactor(bindings/python): simplify async writer aexit (#4128)
Browse files Browse the repository at this point in the history
Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx authored Feb 1, 2024
1 parent f4a3027 commit f2cc712
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions bindings/python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,12 @@ impl AsyncFile {
}

fn __aexit__<'a>(
&self,
&'a mut self,
py: Python<'a>,
_exc_type: &'a PyAny,
_exc_value: &'a PyAny,
_traceback: &'a PyAny,
) -> PyResult<&'a PyAny> {
let state = self.0.clone();
future_into_py(py, async move {
let mut state = state.lock().await;
if let AsyncFileState::Writer(w) = &mut *state {
w.close()
.await
.map_err(|err| PyIOError::new_err(err.to_string()))?;
}
*state = AsyncFileState::Closed;
Ok(())
})
self.close(py)
}
}

0 comments on commit f2cc712

Please sign in to comment.