From 4f91581bee3c8659980ad4b0a6593af58e3b3016 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Thu, 4 Apr 2024 15:21:43 +0100 Subject: [PATCH] chore!: Update pyo3 to 0.21 --- Cargo.toml | 4 ++-- README.md | 2 +- src/pytket.rs | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2fd65a0..c60adbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ name = "tket_json_rs" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" uuid = { version = "1.4", features = ["serde"] } -pyo3 = { version = "0.20.0", optional = true } -pythonize = { version = "0.20.0", optional = true } +pyo3 = { version = "0.21.1", optional = true } +pythonize = { version = "0.21.1", optional = true } [features] diff --git a/README.md b/README.md index 79edbff..207af09 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Serializable Rust definition for circuits and operations of the ## Features -- `pyo3`: Enable Python bindings via pyo3. +- `pyo3`: Enable Python bindings and `pytket.Circuit` conversion via pyo3. ## Recent Changes diff --git a/src/pytket.rs b/src/pytket.rs index df56c68..8486248 100644 --- a/src/pytket.rs +++ b/src/pytket.rs @@ -2,12 +2,12 @@ use crate::circuit_json::SerialCircuit; use pyo3::prelude::*; -use pythonize::{depythonize, pythonize}; +use pythonize::{depythonize_bound, pythonize}; impl SerialCircuit { /// Create a new `SerialCircuit` from a `pytket.Circuit`. - pub fn from_tket1(circ: &PyAny) -> PyResult { - let circ = depythonize(circ.call_method0("to_dict").unwrap())?; + pub fn from_tket1(circ: &Bound) -> PyResult { + let circ = depythonize_bound(circ.call_method0("to_dict").unwrap())?; Ok(circ) } @@ -15,13 +15,13 @@ impl SerialCircuit { /// /// Utility function that calls [`SerialCircuit::from_tket1`] after acquiring the GIL. pub fn from_tket1_with_gil(circ: Py) -> PyResult { - Python::with_gil(|py| Self::from_tket1(circ.as_ref(py))) + Python::with_gil(|py| Self::from_tket1(circ.bind(py))) } /// Convert a `SerialCircuit` to a `pytket.Circuit`. - pub fn to_tket1<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { + pub fn to_tket1<'py>(&self, py: Python<'py>) -> PyResult> { let dict = pythonize(py, self).unwrap(); - let circ_module = PyModule::import(py, "pytket.circuit")?; + let circ_module = PyModule::import_bound(py, "pytket.circuit")?; circ_module .getattr("Circuit")?