From 4bb157d2478a0b85c46dfb865dd3434b74d169a7 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 18 Oct 2024 10:43:02 -0400 Subject: [PATCH] more --- crates/chia-protocol/src/bytes.rs | 4 ++-- crates/chia_py_streamable_macro/src/lib.rs | 12 ++++++++---- wheel/src/api.rs | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/chia-protocol/src/bytes.rs b/crates/chia-protocol/src/bytes.rs index aaf87b2ca..ac3e929fc 100644 --- a/crates/chia-protocol/src/bytes.rs +++ b/crates/chia-protocol/src/bytes.rs @@ -422,7 +422,7 @@ impl ChiaToPython for BytesImpl { #[cfg(feature = "py-bindings")] impl<'py, const N: usize> FromPyObject<'py> for BytesImpl { - fn extract(obj: &'py PyAny) -> PyResult { + fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult { let b = obj.downcast::()?; let slice: &[u8] = b.as_bytes(); let buf: [u8; N] = slice.try_into()?; @@ -453,7 +453,7 @@ impl ChiaToPython for Bytes { #[cfg(feature = "py-bindings")] impl<'py> FromPyObject<'py> for Bytes { - fn extract(obj: &'py PyAny) -> PyResult { + fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult { let b = obj.downcast::()?; Ok(Bytes(b.as_bytes().to_vec())) } diff --git a/crates/chia_py_streamable_macro/src/lib.rs b/crates/chia_py_streamable_macro/src/lib.rs index ad6daf439..9edb3ce06 100644 --- a/crates/chia_py_streamable_macro/src/lib.rs +++ b/crates/chia_py_streamable_macro/src/lib.rs @@ -47,7 +47,8 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS syn::Data::Enum(_) => { return quote! { impl<'a> pyo3::conversion::FromPyObject<'a> for #ident { - fn extract(ob: &'a pyo3::PyAny) -> pyo3::PyResult { + fn extract_bound(ob: &pyo3::Bound<'a, pyo3::PyAny>) -> pyo3::PyResult { + use pyo3::types::PyAnyMethods; let v: u8 = ob.extract()?; ::parse::(&mut std::io::Cursor::<&[u8]>::new(&[v])).map_err(|e| e.into()) } @@ -132,11 +133,13 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS #[pyo3::pymethods] impl #ident { #[pyo3(signature = (**kwargs))] - fn replace(&self, kwargs: Option<&pyo3::types::PyDict>) -> pyo3::PyResult { + fn replace(&self, kwargs: Option<&pyo3::Bound>) -> pyo3::PyResult { let mut ret = self.clone(); if let Some(kwargs) = kwargs { - let iter: pyo3::types::iter::PyDictIterator = kwargs.iter(); + use pyo3::prelude::PyDictMethods; + let iter = kwargs.iter(); for (field, value) in iter { + use pyo3::prelude::PyAnyMethods; let field = field.extract::()?; match field.as_str() { #(stringify!(#fnames_maybe_upper) => { @@ -323,9 +326,10 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS impl #ident { pub fn __setstate__( &mut self, - state: &pyo3::types::PyBytes, + state: &pyo3::Bound, ) -> pyo3::PyResult<()> { use chia_traits::Streamable; + use pyo3::types::PyBytesMethods; *self = Self::parse::(&mut std::io::Cursor::new(state.as_bytes()))?; diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 3802c2023..581e1e73d 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -78,10 +78,11 @@ use chia_bls::{ #[pyfunction] pub fn compute_merkle_set_root<'p>( py: Python<'p>, - values: Vec<&'p PyBytes>, + values: Vec>, ) -> PyResult> { let mut buffer = Vec::<[u8; 32]>::with_capacity(values.len()); for b in values { + use pyo3::types::PyBytesMethods; buffer.push(b.as_bytes().try_into()?); } Ok(PyBytes::new_bound(