Skip to content

Commit b0fa916

Browse files
committed
Bumpver and migrate to pyo3 0.24.2
1 parent 34335f1 commit b0fa916

29 files changed

Lines changed: 103 additions & 100 deletions

.github/workflows/CI.yml

776 Bytes
Binary file not shown.

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bfp-rs"
3-
version = "0.3.0-alpha17"
3+
version = "0.3.0-alpha18"
44
edition = "2021"
55

66
[profile.release]
@@ -23,7 +23,7 @@ name = "bfp_rs"
2323
crate-type = ["cdylib"]
2424

2525
[dependencies]
26-
pyo3 = "0.22.0"
26+
pyo3 = "0.24.2"
2727
encoding_rs = "0.8.35"
2828
indicatif = "0.17.11"
2929
serde = "1.0.219"

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub mod combinators;
5353
pub mod help;
5454

5555
fn le(py: Python, types: &Bound<PyModule>) -> PyResult<()> {
56-
let le = PyModule::new_bound(types.py(), "bfp_rs.types.le")?;
56+
let le = PyModule::new(types.py(), "bfp_rs.types.le")?;
5757
py_run!(py, le, "import sys; sys.modules['bfp_rs.types.le'] = le");
5858
types.add_submodule(&le)?;
5959

@@ -136,7 +136,7 @@ fn le(py: Python, types: &Bound<PyModule>) -> PyResult<()> {
136136
}
137137

138138
fn types(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
139-
let types = PyModule::new_bound(bfp.py(), "bfp_rs.types")?;
139+
let types = PyModule::new(bfp.py(), "bfp_rs.types")?;
140140
py_run!(py, types, "import sys; sys.modules['bfp_rs.types'] = types");
141141
bfp.add_submodule(&types)?;
142142

@@ -146,7 +146,7 @@ fn types(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
146146
}
147147

148148
fn combinators(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
149-
let combinators = &PyModule::new_bound(bfp.py(), "bfp_rs.combinators")?;
149+
let combinators = &PyModule::new(bfp.py(), "bfp_rs.combinators")?;
150150
py_run!(py, combinators, "import sys; sys.modules['bfp_rs.combinators'] = combinators");
151151
bfp.add_submodule(combinators)?;
152152

@@ -170,20 +170,20 @@ fn combinators(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
170170
}
171171

172172
fn errors(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
173-
let errors = PyModule::new_bound(bfp.py(), "bfp_rs.errors")?;
173+
let errors = PyModule::new(bfp.py(), "bfp_rs.errors")?;
174174
py_run!(py, errors, "import sys; sys.modules['bfp_rs.errors'] = errors");
175175
bfp.add_submodule(&errors)?;
176-
errors.add("ParsingError", py.get_type_bound::<ParsingError>())?;
177-
errors.add("CompressionError", py.get_type_bound::<CompressionError>())?;
178-
errors.add("DefaultValueError", py.get_type_bound::<DefaultAttributeError>())?;
179-
errors.add("VersionError", py.get_type_bound::<VersionError>())?;
180-
errors.add("MutabilityError", py.get_type_bound::<MutabilityError>())?;
176+
errors.add("ParsingError", py.get_type::<ParsingError>())?;
177+
errors.add("CompressionError", py.get_type::<CompressionError>())?;
178+
errors.add("DefaultValueError", py.get_type::<DefaultAttributeError>())?;
179+
errors.add("VersionError", py.get_type::<VersionError>())?;
180+
errors.add("MutabilityError", py.get_type::<MutabilityError>())?;
181181

182182
Ok(())
183183
}
184184

185185
fn diff(py: Python, bfp: &Bound<PyModule>) -> PyResult<()> {
186-
let diff = PyModule::new_bound(bfp.py(), "bfp_rs.diff")?;
186+
let diff = PyModule::new(bfp.py(), "bfp_rs.diff")?;
187187
py_run!(py, diff, "import sys; sys.modules['bfp_rs.diff'] = diff");
188188
bfp.add_submodule(&diff)?;
189189

src/macros/wrap_py.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! wrap_py {
66
#[pyo3(name = "to_bytes")]
77
fn to_bytes_py(slf: PyRef<Self>, value: <Self as Parseable>::Type) -> PyResult<Bound<PyBytes>> {
88
let bytes = slf.to_bytes(&value)?;
9-
Ok(PyBytes::new_bound(slf.py(), &bytes))
9+
Ok(PyBytes::new(slf.py(), &bytes))
1010
}
1111

1212
#[pyo3(name = "from_stream", signature = (stream, ver = Version::new(vec![0,])))]

src/retrievers/retriever.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Retriever {
190190
"List length mismatch for '{}' which is a retriever of fixed repeat. Expected: {repeat}, Actual: {len}", slf.name
191191
)))
192192
}
193-
let value = value.iter()?
193+
let value = value.try_iter()?
194194
.map(|v| {
195195
slf.data_type.to_parseable(&v.expect("obtained from python"))
196196
}).collect::<PyResult<Vec<_>>>()?;
@@ -231,9 +231,9 @@ impl Retriever {
231231

232232
if let Some(default_factory) = self.default_factory.as_ref() {
233233
let first_default = default_factory
234-
.call_bound(py, (ver.clone(),) , None)
234+
.call(py, (ver.clone(),) , None)
235235
.or_else(|_err| {
236-
default_factory.call_bound(py, (ver.clone(), ctx.clone()) , None)
236+
default_factory.call(py, (ver.clone(), ctx.clone()) , None)
237237
})?
238238
.into_bound(py);
239239
if state == RetState::Value {
@@ -260,9 +260,9 @@ impl Retriever {
260260

261261
for _ in 1..repeat {
262262
let default = default_factory
263-
.call_bound(py, (ver.clone(),), None)
263+
.call(py, (ver.clone(),), None)
264264
.or_else(|_err| {
265-
default_factory.call_bound(py, (ver.clone(), ctx.clone()) , None)
265+
default_factory.call(py, (ver.clone(), ctx.clone()) , None)
266266
})?
267267
.into_bound(py);
268268
ls.push(self.data_type.to_parseable(&default)?);

src/retrievers/retriever_ref.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::OnceCell;
2+
use std::ffi::CString;
23
use std::sync::Arc;
34
use pyo3::exceptions::{PyTypeError, PyValueError};
45
use pyo3::intern;
@@ -45,8 +46,8 @@ impl RetrieverRef {
4546
let enum_ = match r#enum {
4647
None => None,
4748
Some(cls) => {
48-
let globals = PyDict::new_bound(cls.py());
49-
cls.py().run_bound("from enum import Enum", Some(&globals), None)?;
49+
let globals = PyDict::new(cls.py());
50+
cls.py().run(&CString::new("from enum import Enum")?, Some(&globals), None)?;
5051
let enum_cls = globals.get_item("Enum")?.expect("infallible");
5152

5253
if !cls.is_subclass(&enum_cls)? {
@@ -132,10 +133,10 @@ impl RetrieverRef {
132133
Ok(current)
133134
}
134135

135-
fn __set__(
136-
slf: Bound<Self>,
137-
mut instance: Bound<PyAny>,
138-
mut value: Bound<PyAny>,
136+
fn __set__<'py>(
137+
slf: Bound<'py, Self>,
138+
mut instance: Bound<'py, PyAny>,
139+
mut value: Bound<'py, PyAny>,
139140
) -> PyResult<()> {
140141
let this = slf.borrow();
141142
if let Some(cls) = &this.enum_ {

src/types/base_struct.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ impl BaseStruct {
9797

9898
// todo: figure out unsafe allocations
9999
pub fn with_cls<'py>(val: BaseStruct, cls: &Bound<'py, PyType>) -> PyResult<Bound<'py, PyAny>> {
100-
let kwargs = PyDict::new_bound(cls.py());
101-
kwargs.set_item("ver", Version::new(vec![-1]).into_py(cls.py()))?;
102-
kwargs.set_item("ctx", ContextPtr::new().into_py(cls.py()))?;
100+
let kwargs = PyDict::new(cls.py());
101+
kwargs.set_item("ver", Version::new(vec![-1]).into_pyobject(cls.py())?)?;
102+
kwargs.set_item("ctx", ContextPtr::new().into_pyobject(cls.py())?)?;
103103
kwargs.set_item("init_defaults", false)?;
104104
let obj = cls.call_method(intern!(cls.py(), "__new__"), (cls,), Some(&kwargs))?;
105105
let name = intern!(cls.py(), "__reconstruct__");
@@ -223,10 +223,13 @@ impl BaseStruct {
223223
#[classmethod]
224224
fn retrievers<'py>(cls: &Bound<'py, PyType>) -> PyResult<Bound<'py, PyList>> {
225225
let struct_ = StructBuilder::get_struct(&cls)?;
226-
Ok(PyList::new_bound(
226+
PyList::new(
227227
cls.py(),
228-
struct_.retrievers().iter().map(|x| x.clone().into_py(cls.py()))
229-
))
228+
struct_.retrievers()
229+
.iter()
230+
.map(|x| x.clone().into_pyobject(cls.py()))
231+
.collect::<Result<Vec<_>, _>>()?
232+
)
230233
}
231234

232235
#[new]
@@ -315,7 +318,7 @@ impl BaseStruct {
315318
if struct_.is_compressed() {
316319
struct_.compress(&mut bytes, 0)?;
317320
}
318-
Ok(PyBytes::new_bound(cls.py(), &bytes).into_any())
321+
Ok(PyBytes::new(cls.py(), &bytes).into_any())
319322
}
320323

321324
#[classmethod]

src/types/bfp_list.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::RwLock;
66
use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
77
use pyo3::prelude::{PyAnyMethods, PyDictMethods, PyTypeMethods};
88
use pyo3::types::{PyDict, PyInt, PySlice, PySliceIndices, PySliceMethods};
9-
use pyo3::{pyclass, pymethods, Bound, IntoPy, PyAny, PyRef, PyRefMut, PyResult, Python};
9+
use pyo3::{pyclass, pymethods, Bound, IntoPyObjectExt, PyAny, PyRef, PyRefMut, PyResult, Python};
1010
use serde::{Serialize, Serializer};
1111
use crate::errors::mutability_error::MutabilityError;
1212
use crate::types::bfp_type::BfpType;
@@ -93,7 +93,7 @@ impl BfpList {
9393
return Err(MutabilityError::new_err("This list is set as immutable by it's API designer"));
9494
}
9595

96-
let mut vals = val.iter()?
96+
let mut vals = val.try_iter()?
9797
.map(|v| {
9898
inner.data_type.to_parseable(&v.expect("obtained from python"))
9999
})
@@ -259,8 +259,7 @@ impl BfpList {
259259
idxes.into_iter()
260260
.map(|idx| inner.data[idx].clone().to_bound(slf.py()))
261261
.collect::<PyResult<Vec<_>>>()?
262-
.into_py(slf.py())
263-
.into_bound(slf.py())
262+
.into_bound_py_any(slf.py())?
264263
)
265264
}
266265
Err(PyIndexError::new_err(
@@ -287,7 +286,7 @@ impl BfpList {
287286
let item = item.downcast_into::<PySlice>().expect("infallible");
288287
let idxes = slice(item.indices(inner.data.len() as isize)?)?;
289288

290-
let vals = val.iter()?
289+
let vals = val.try_iter()?
291290
.map(|v| v.expect("obtained from python"))
292291
.collect::<Vec<_>>();
293292
if idxes.len() != vals.len() {
@@ -479,7 +478,7 @@ impl BfpList {
479478

480479
impl BfpList {
481480
pub fn diffs_to_dict<'py>(&self, changes: Vec<IDiff<ParseableType>>, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
482-
let di = PyDict::new_bound(py);
481+
let di = PyDict::new(py);
483482
let inner = self.inner();
484483
for (idx, change) in changes {
485484
PyDictMethods::set_item(
@@ -492,7 +491,7 @@ impl BfpList {
492491
}
493492

494493
pub fn conflicts_to_dict<'py>(&self, conflicts: Vec<Conflict<ParseableType>>, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
495-
let di = PyDict::new_bound(py);
494+
let di = PyDict::new(py);
496495
let mut inner = self.inner_mut();
497496
for conflict in conflicts {
498497
let idx = conflict.idx();

src/types/bfp_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl BfpType {
398398
#[pyo3(name = "to_bytes")]
399399
fn to_bytes_py<'py>(slf: PyRef<'py, Self>, value: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyBytes>> {
400400
let bytes = slf.to_bytes(&slf.to_parseable(value)?)?;
401-
Ok(PyBytes::new_bound(slf.py(), &bytes))
401+
Ok(PyBytes::new(slf.py(), &bytes))
402402
}
403403

404404
#[pyo3(name = "from_stream", signature = (stream, ver = Version::new(vec![0,])))]

0 commit comments

Comments
 (0)