From 1bf6d7e6fadbb84bdad5729e0ab9e9170a920d0a Mon Sep 17 00:00:00 2001 From: Jane Doe Date: Thu, 18 Apr 2024 23:13:20 +0200 Subject: [PATCH] Update for pyo3 0.21. --- examples/python-extension/Cargo.toml | 2 +- examples/python-extension/src/lib.rs | 4 ++-- pyo3-tch/Cargo.toml | 2 +- pyo3-tch/src/lib.rs | 5 +---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/python-extension/Cargo.toml b/examples/python-extension/Cargo.toml index 8bb57a24..f56fe003 100644 --- a/examples/python-extension/Cargo.toml +++ b/examples/python-extension/Cargo.toml @@ -17,7 +17,7 @@ name = "tch_ext" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.18.3", features = ["extension-module"] } +pyo3 = { version = "0.21", features = ["extension-module"] } pyo3-tch = { path = "../../pyo3-tch", version = "0.15.0" } tch = { path = "../..", features = ["python-extension"], version = "0.15.0" } torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.15.0" } diff --git a/examples/python-extension/src/lib.rs b/examples/python-extension/src/lib.rs index fc6f1c6e..3e7a102c 100644 --- a/examples/python-extension/src/lib.rs +++ b/examples/python-extension/src/lib.rs @@ -10,8 +10,8 @@ fn add_one(tensor: PyTensor) -> PyResult { /// A Python module implemented in Rust using tch to manipulate PyTorch /// objects. #[pymodule] -fn tch_ext(py: Python<'_>, m: &PyModule) -> PyResult<()> { - py.import("torch")?; +fn tch_ext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { + py.import_bound("torch")?; m.add_function(wrap_pyfunction!(add_one, m)?)?; Ok(()) } diff --git a/pyo3-tch/Cargo.toml b/pyo3-tch/Cargo.toml index 61b06a3e..c1fde9f2 100644 --- a/pyo3-tch/Cargo.toml +++ b/pyo3-tch/Cargo.toml @@ -14,4 +14,4 @@ license = "MIT/Apache-2.0" [dependencies] tch = { path = "..", features = ["python-extension"], version = "0.15.0" } torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.15.0" } -pyo3 = { version = "0.18.3", features = ["extension-module"] } +pyo3 = { version = "0.21", features = ["extension-module"] } diff --git a/pyo3-tch/src/lib.rs b/pyo3-tch/src/lib.rs index b95cdd2f..3be3fa08 100644 --- a/pyo3-tch/src/lib.rs +++ b/pyo3-tch/src/lib.rs @@ -1,8 +1,5 @@ +use pyo3::exceptions::{PyTypeError, PyValueError}; use pyo3::prelude::*; -use pyo3::{ - exceptions::{PyTypeError, PyValueError}, - AsPyPointer, -}; pub use tch; pub use torch_sys;