Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade pyo3 to 0.23 #5368

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

XmchxUp
Copy link
Contributor

@XmchxUp XmchxUp commented Nov 29, 2024

Which issue does this PR close?

Closes #5336.

Sorry, my skills are limited and I may not have made the changes correctly.

However, all the tests have passed, but I still don't know how to make the changes here. Can someone help me?

opendal/bindings/python/src/lister.rs

#[pymethods]
impl AsyncLister {
    fn __aiter__(slf: PyRef<'_, Self>) -> PyRef<Self> {
        slf
    }
    fn __anext__(slf: PyRefMut<'_, Self>) -> PyResult<Option<PyObject>> {
        let lister = slf.0.clone();
        let fut = future_into_py(slf.py(), async move {
            let mut lister = lister.lock().await;
            let entry = lister.try_next().await.map_err(format_pyerr)?;
            match entry {
                Some(entry) => Ok(Python::with_gil(|py| Entry::new(entry).into_py(py))),
                None => Err(PyStopAsyncIteration::new_err("stream exhausted")),
            }
        })?;
        Ok(Some(fut.into()))
    }
}

@Zheaoli
Copy link
Member

Zheaoli commented Nov 29, 2024

However, all the tests have passed, but I still don't know how to make the changes here. Can someone help me?

What do you want to do for AsyncLister in this PR?

@XmchxUp
Copy link
Contributor Author

XmchxUp commented Nov 30, 2024

What do you want to do for AsyncLister in this PR?

Originally it was intended to continue to change towards this, Entry::new(entry).into_pyobject(py)? .into_any().unbind(), but there are some type matches, didn't think about how to change it.

Updated now.

@messense messense changed the title feat: upgrade pyo03 to 0.23 feat: upgrade pyo3 to 0.23 Nov 30, 2024
@XmchxUp
Copy link
Contributor Author

XmchxUp commented Dec 2, 2024

I think the modification for file.rs may have lost the original meaning, this modification is a bit difficult for me.

@Zheaoli @messense

@messense
Copy link
Member

messense commented Dec 2, 2024

Here is a patch to simplify this PR (I can't push to your branch):

commit 7590c5f11c04a63a85ef32f4e5e818024acb34a4
Author: messense <messense@icloud.com>
Date:   Mon Dec 2 13:26:59 2024 +0000

    simplify

diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index 8cfcbf51..2c217232 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -470,8 +470,7 @@ impl AsyncFile {
                 .map_err(|err| PyIOError::new_err(err.to_string()))?;
             Ok(pos)
         })
-        .and_then(|pos| pos.into_pyobject(py).map_err(Into::into))
-        .map(|pyobj| pyobj.into_any())
+        .and_then(|pos| pos.into_bound_py_any(py))
     }
 
     /// Return the current stream position.
@@ -500,8 +499,7 @@ impl AsyncFile {
                 .map_err(|err| PyIOError::new_err(err.to_string()))?;
             Ok(pos)
         })
-        .and_then(|pos| pos.into_pyobject(py).map_err(Into::into))
-        .map(|pyobj| pyobj.into_any())
+        .and_then(|pos| pos.into_bound_py_any(py))
     }
 
     fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
diff --git a/bindings/python/src/lister.rs b/bindings/python/src/lister.rs
index 55e08bef..6019689d 100644
--- a/bindings/python/src/lister.rs
+++ b/bindings/python/src/lister.rs
@@ -42,12 +42,7 @@ impl BlockingLister {
     }
     fn __next__(mut slf: PyRefMut<'_, Self>) -> PyResult<Option<PyObject>> {
         match slf.0.next() {
-            Some(Ok(entry)) => Ok(Some(
-                Entry::new(entry)
-                    .into_pyobject(slf.py())?
-                    .into_any()
-                    .unbind(),
-            )),
+            Some(Ok(entry)) => Ok(Some(Entry::new(entry).into_py_any(slf.py())?)),
             Some(Err(err)) => {
                 let pyerr = format_pyerr(err);
                 Err(pyerr)
diff --git a/bindings/python/src/operator.rs b/bindings/python/src/operator.rs
index 995f3b74..76cdb09f 100644
--- a/bindings/python/src/operator.rs
+++ b/bindings/python/src/operator.rs
@@ -230,9 +230,9 @@ impl Operator {
 
     fn __getnewargs_ex__(&self, py: Python) -> PyResult<PyObject> {
         let args = vec![self.__scheme.to_string()];
-        let args = PyTuple::new(py, args)?.into_any().unbind();
+        let args = PyTuple::new(py, args)?.into_py_any(py)?;
         let kwargs = self.__map.clone().into_py_any(py)?;
-        Ok(PyTuple::new(py, [args, kwargs])?.into_any().unbind())
+        Ok(PyTuple::new(py, [args, kwargs])?.into_py_any(py)?)
     }
 }
 
@@ -435,13 +435,7 @@ impl AsyncOperator {
         let this = self.core.clone();
         future_into_py(py, async move {
             let lister = this.lister(&path).await.map_err(format_pyerr)?;
-
-            let pylister = Python::with_gil(|py| {
-                AsyncLister::new(lister)
-                    .into_pyobject(py)
-                    .map_err(|err| PyErr::new::<pyo3::exceptions::PyException, _>(err.to_string()))
-                    .map(|py_obj| py_obj.into_any().unbind())
-            })?;
+            let pylister = Python::with_gil(|py| AsyncLister::new(lister).into_py_any(py))?;
 
             Ok(pylister)
         })
@@ -456,12 +450,8 @@ impl AsyncOperator {
                 .recursive(true)
                 .await
                 .map_err(format_pyerr)?;
-            let pylister: PyObject = Python::with_gil(|py| {
-                AsyncLister::new(lister)
-                    .into_pyobject(py)
-                    .map_err(|err| PyErr::new::<pyo3::exceptions::PyException, _>(err.to_string()))
-                    .map(|py_obj| py_obj.into_any().unbind())
-            })?;
+            let pylister: PyObject =
+                Python::with_gil(|py| AsyncLister::new(lister).into_py_any(py))?;
             Ok(pylister)
         })
     }
@@ -559,7 +549,7 @@ impl AsyncOperator {
         let args = vec![self.__scheme.to_string()];
         let args = PyTuple::new(py, args)?.into_py_any(py)?;
         let kwargs = self.__map.clone().into_py_any(py)?;
-        Ok(PyTuple::new(py, [args, kwargs])?.into_any().unbind())
+        Ok(PyTuple::new(py, [args, kwargs])?.into_py_any(py)?)
     }
 }

you can save it to a file say 1.patch then run git apply < 1.patch on this branch.

@XmchxUp
Copy link
Contributor Author

XmchxUp commented Dec 3, 2024

Here is a patch to simplify this PR (I can't push to your branch):

commit 7590c5f11c04a63a85ef32f4e5e818024acb34a4
Author: messense <messense@icloud.com>
Date:   Mon Dec 2 13:26:59 2024 +0000

    simplify

diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs
index 8cfcbf51..2c217232 100644
--- a/bindings/python/src/file.rs
+++ b/bindings/python/src/file.rs
@@ -470,8 +470,7 @@ impl AsyncFile {
                 .map_err(|err| PyIOError::new_err(err.to_string()))?;
             Ok(pos)
         })
-        .and_then(|pos| pos.into_pyobject(py).map_err(Into::into))
-        .map(|pyobj| pyobj.into_any())
+        .and_then(|pos| pos.into_bound_py_any(py))
     }
 
     /// Return the current stream position.
@@ -500,8 +499,7 @@ impl AsyncFile {
                 .map_err(|err| PyIOError::new_err(err.to_string()))?;
             Ok(pos)
         })
-        .and_then(|pos| pos.into_pyobject(py).map_err(Into::into))
-        .map(|pyobj| pyobj.into_any())
+        .and_then(|pos| pos.into_bound_py_any(py))
     }
 
     fn close<'p>(&'p mut self, py: Python<'p>) -> PyResult<Bound<PyAny>> {
diff --git a/bindings/python/src/lister.rs b/bindings/python/src/lister.rs
index 55e08bef..6019689d 100644
--- a/bindings/python/src/lister.rs
+++ b/bindings/python/src/lister.rs
@@ -42,12 +42,7 @@ impl BlockingLister {
     }
     fn __next__(mut slf: PyRefMut<'_, Self>) -> PyResult<Option<PyObject>> {
         match slf.0.next() {
-            Some(Ok(entry)) => Ok(Some(
-                Entry::new(entry)
-                    .into_pyobject(slf.py())?
-                    .into_any()
-                    .unbind(),
-            )),
+            Some(Ok(entry)) => Ok(Some(Entry::new(entry).into_py_any(slf.py())?)),
             Some(Err(err)) => {
                 let pyerr = format_pyerr(err);
                 Err(pyerr)
diff --git a/bindings/python/src/operator.rs b/bindings/python/src/operator.rs
index 995f3b74..76cdb09f 100644
--- a/bindings/python/src/operator.rs
+++ b/bindings/python/src/operator.rs
@@ -230,9 +230,9 @@ impl Operator {
 
     fn __getnewargs_ex__(&self, py: Python) -> PyResult<PyObject> {
         let args = vec![self.__scheme.to_string()];
-        let args = PyTuple::new(py, args)?.into_any().unbind();
+        let args = PyTuple::new(py, args)?.into_py_any(py)?;
         let kwargs = self.__map.clone().into_py_any(py)?;
-        Ok(PyTuple::new(py, [args, kwargs])?.into_any().unbind())
+        Ok(PyTuple::new(py, [args, kwargs])?.into_py_any(py)?)
     }
 }
 
@@ -435,13 +435,7 @@ impl AsyncOperator {
         let this = self.core.clone();
         future_into_py(py, async move {
             let lister = this.lister(&path).await.map_err(format_pyerr)?;
-
-            let pylister = Python::with_gil(|py| {
-                AsyncLister::new(lister)
-                    .into_pyobject(py)
-                    .map_err(|err| PyErr::new::<pyo3::exceptions::PyException, _>(err.to_string()))
-                    .map(|py_obj| py_obj.into_any().unbind())
-            })?;
+            let pylister = Python::with_gil(|py| AsyncLister::new(lister).into_py_any(py))?;
 
             Ok(pylister)
         })
@@ -456,12 +450,8 @@ impl AsyncOperator {
                 .recursive(true)
                 .await
                 .map_err(format_pyerr)?;
-            let pylister: PyObject = Python::with_gil(|py| {
-                AsyncLister::new(lister)
-                    .into_pyobject(py)
-                    .map_err(|err| PyErr::new::<pyo3::exceptions::PyException, _>(err.to_string()))
-                    .map(|py_obj| py_obj.into_any().unbind())
-            })?;
+            let pylister: PyObject =
+                Python::with_gil(|py| AsyncLister::new(lister).into_py_any(py))?;
             Ok(pylister)
         })
     }
@@ -559,7 +549,7 @@ impl AsyncOperator {
         let args = vec![self.__scheme.to_string()];
         let args = PyTuple::new(py, args)?.into_py_any(py)?;
         let kwargs = self.__map.clone().into_py_any(py)?;
-        Ok(PyTuple::new(py, [args, kwargs])?.into_any().unbind())
+        Ok(PyTuple::new(py, [args, kwargs])?.into_py_any(py)?)
     }
 }

you can save it to a file say 1.patch then run git apply < 1.patch on this branch.

thank you.

Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@messense messense merged commit a686ba3 into apache:main Dec 3, 2024
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new feature: Upgrade pyo3 to 0.23
3 participants