From 1168387170563a450d0bf2dddb882ed4584cc513 Mon Sep 17 00:00:00 2001 From: Steve C Date: Fri, 15 Nov 2024 23:03:00 -0500 Subject: [PATCH] Update pyo3 (#44) --- Cargo.toml | 2 +- src/arena.rs | 10 ++++------ src/bets.rs | 10 +++++----- src/math.rs | 21 ++++++++++----------- src/nfc.rs | 14 ++++++++------ src/pirates.rs | 4 ++-- uv.lock | 2 +- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d5f975a..30f27f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "neofoodclub" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.22.6", features = ["extension-module", "abi3-py311", "chrono", "chrono-tz"] } +pyo3 = { version = "0.23.0", features = ["extension-module", "abi3-py311", "chrono", "chrono-tz"] } neofoodclub = { path = "./neofoodclub_rs" } chrono = "0.4.38" chrono-tz = "0.10.0" diff --git a/src/arena.rs b/src/arena.rs index 742dcba..8b218f5 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -25,10 +25,8 @@ impl Arena { #[getter] fn foods<'a>(&self, py: Python<'a>) -> PyResult>> { - let elements = &self.inner.foods; - - match elements { - Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))), + match self.inner.foods { + Some(foods) => Ok(Some(PyTuple::new(py, foods)?)), None => Ok(None), } } @@ -55,7 +53,7 @@ impl Arena { #[getter] fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult> { let elements = &self.inner.ids(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] @@ -180,7 +178,7 @@ impl Arenas { .iter() .map(|a| a.pirate_ids(py).expect("failed to get pirate ids")) .collect(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] diff --git a/src/bets.rs b/src/bets.rs index bcccebf..9562caa 100644 --- a/src/bets.rs +++ b/src/bets.rs @@ -25,7 +25,7 @@ impl Bets { let elements = &self.inner.bet_amounts; match elements { - Some(amounts) => Ok(Some(PyTuple::new_bound(py, amounts))), + Some(amounts) => Ok(Some(PyTuple::new(py, amounts)?)), None => Ok(None), } } @@ -60,7 +60,7 @@ impl Bets { #[getter] fn binaries<'a>(&self, py: Python<'a>) -> PyResult> { - Ok(PyTuple::new_bound(py, self.inner.get_binaries())) + PyTuple::new(py, self.inner.get_binaries()) } #[getter] @@ -104,12 +104,12 @@ impl Bets { #[getter] fn indices<'a>(&self, py: Python<'a>) -> PyResult> { let indicies = self.inner.get_indices(); - let py_indicies: Vec> = indicies + let py_indicies: Result>, PyErr> = indicies .iter() - .map(|index| PyTuple::new_bound(py, index)) + .map(|index| PyTuple::new(py, index)) .collect(); - Ok(PyTuple::new_bound(py, py_indicies)) + PyTuple::new(py, py_indicies?) } fn net_expected(&self, nfc: &NeoFoodClub) -> f64 { diff --git a/src/math.rs b/src/math.rs index 2aa0bcf..295d040 100644 --- a/src/math.rs +++ b/src/math.rs @@ -31,7 +31,7 @@ impl Math { #[staticmethod] fn binary_to_indices(py: Python<'_>, binary: u32) -> PyResult> { let elements = neofoodclub::math::binary_to_indices(binary); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[staticmethod] @@ -40,7 +40,7 @@ impl Math { bets_hash: &'a str, ) -> PyResult> { let elements = neofoodclub::math::bets_hash_to_bet_indices(bets_hash); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[staticmethod] @@ -59,7 +59,7 @@ impl Math { amounts_hash: &'a str, ) -> PyResult> { let elements = neofoodclub::math::amounts_hash_to_bet_amounts(amounts_hash); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[staticmethod] @@ -68,7 +68,7 @@ impl Math { bets_hash: &'a str, ) -> PyResult> { let elements = neofoodclub::math::bets_hash_to_bet_binaries(bets_hash); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[staticmethod] @@ -82,7 +82,7 @@ impl Math { bets_indices: Vec<[u8; 5]>, ) -> PyResult> { let elements = neofoodclub::math::bets_indices_to_bet_binaries(bets_indices); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[staticmethod] @@ -92,13 +92,12 @@ impl Math { bet_odds: Vec, probabilities: [[f64; 5]; 5], ) -> PyResult> { - let py_structs: Vec = - neofoodclub::math::build_chance_objects(&bets, &bet_odds, probabilities) - .into_iter() - .map(|chance| Chance::from(chance).into_py(py)) - .collect(); + let py_structs = neofoodclub::math::build_chance_objects(&bets, &bet_odds, probabilities) + .into_iter() + .map(|chance| Chance::from(chance).into_pyobject(py)) + .collect::, _>>()?; - Ok(PyTuple::new_bound(py, py_structs)) + PyTuple::new(py, py_structs) } #[staticmethod] diff --git a/src/nfc.rs b/src/nfc.rs index 00584a6..3dc8a61 100644 --- a/src/nfc.rs +++ b/src/nfc.rs @@ -19,6 +19,8 @@ pub struct NeoFoodClub { pub inner: neofoodclub::nfc::NeoFoodClub, } +unsafe impl Sync for NeoFoodClub {} + fn convert_probability_model_int_to_enum( probability_model: Option, ) -> Option { @@ -132,7 +134,7 @@ impl NeoFoodClub { #[getter] fn winners<'a>(&self, py: Python<'a>) -> PyResult> { let elements = self.inner.winners(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] @@ -163,25 +165,25 @@ impl NeoFoodClub { #[getter] fn current_odds<'a>(&self, py: Python<'a>) -> PyResult> { let elements = self.inner.current_odds(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] fn custom_odds<'a>(&self, py: Python<'a>) -> PyResult> { let elements = self.inner.custom_odds(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] fn opening_odds<'a>(&self, py: Python<'a>) -> PyResult> { let elements = self.inner.opening_odds(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] fn pirates<'a>(&self, py: Python<'a>) -> PyResult> { let elements = self.inner.pirates(); - Ok(PyTuple::new_bound(py, elements)) + PyTuple::new(py, elements) } #[getter] @@ -212,7 +214,7 @@ impl NeoFoodClub { let elements = self.inner.foods(); match elements { - Some(e) => Ok(Some(PyTuple::new_bound(py, e))), + Some(e) => Ok(Some(PyTuple::new(py, e)?)), None => Ok(None), } } diff --git a/src/pirates.rs b/src/pirates.rs index fabb7ca..2666ed9 100644 --- a/src/pirates.rs +++ b/src/pirates.rs @@ -143,7 +143,7 @@ impl Pirate { let elements = self.inner.positive_foods(&nfc.inner); match elements { - Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))), + Some(foods) => Ok(Some(PyTuple::new(py, foods)?)), None => Ok(None), } } @@ -156,7 +156,7 @@ impl Pirate { let elements = self.inner.negative_foods(&nfc.inner); match elements { - Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))), + Some(foods) => Ok(Some(PyTuple::new(py, foods)?)), None => Ok(None), } } diff --git a/uv.lock b/uv.lock index ebe7cc0..9dca1f2 100644 --- a/uv.lock +++ b/uv.lock @@ -68,7 +68,7 @@ wheels = [ ] [[package]] -name = "neofoodclub-py" +name = "neofoodclub" version = "1.0.13" source = { editable = "." }