Upgrade to PyO3 0.23

This commit is contained in:
Dirkjan Ochtman 2024-11-15 22:52:39 +01:00
parent 6cd525c6a6
commit 8861aa7865
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View File

@ -18,5 +18,5 @@ crate-type = ["cdylib"]
[dependencies]
bincode = "1.3.2"
instant-segment = { version = "0.11", path = "../instant-segment", features = ["with-serde"] }
pyo3 = { version = "0.22", features = ["extension-module"] }
pyo3 = { version = "0.23", features = ["extension-module"] }
smartstring = "1"

View File

@ -34,7 +34,7 @@ impl Segmenter {
#[new]
fn new(unigrams: &Bound<'_, PyIterator>, bigrams: &Bound<'_, PyIterator>) -> PyResult<Self> {
let unigrams = unigrams
.iter()?
.try_iter()?
.map(|result| {
let item = result?;
let key = item.get_item(0)?;
@ -46,7 +46,7 @@ impl Segmenter {
.collect::<Result<Vec<_>, PyErr>>()?;
let bigrams = bigrams
.iter()?
.try_iter()?
.map(|item| {
let item = item?;
@ -108,7 +108,7 @@ impl Segmenter {
/// this `Segmenter`. Will return `None` iff given an empty iterator argument.
fn score_sentence(&self, words: &Bound<'_, PyIterator>) -> PyResult<Option<f64>> {
let words = words
.iter()?
.try_iter()?
.map(|result| result?.extract::<PyBackedStr>())
.collect::<Result<Vec<_>, _>>()?;
Ok(self.inner.score_sentence(words.iter().map(|s| &**s)))