You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/02/01 13:53:44 UTC

(opendal) branch main updated: refactor(bindings/python): simplify async writer aexit (#4128)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new f2cc712062 refactor(bindings/python): simplify async writer aexit (#4128)
f2cc712062 is described below

commit f2cc7120629adf1966112e02aac8e3b56c183ec5
Author: Suyan <su...@gmail.com>
AuthorDate: Thu Feb 1 21:53:34 2024 +0800

    refactor(bindings/python): simplify async writer aexit (#4128)
    
    Signed-off-by: suyanhanx <su...@gmail.com>
---
 bindings/python/src/file.rs | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index 692bb4896d..552903b489 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -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)
     }
 }