Skip to content

Commit 0f3ed05

Browse files
committed
updated dependencies, including pyo3 0.27.2
1 parent 17ff2ce commit 0f3ed05

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stam-python"
3-
version = "0.12.0"
3+
version = "0.12.1"
44
edition = "2021"
55
authors = ["Maarten van Gompel <[email protected]>"]
66
description = "STAM is a library for dealing with standoff annotations on text, this is the python binding."
@@ -17,10 +17,10 @@ name = "stam"
1717
crate-type = ["cdylib"]
1818

1919
[dependencies]
20-
pyo3 = { version = "0.26.0", features = ["chrono"] }
20+
pyo3 = { version = "0.27.2", features = ["chrono"] }
2121
rayon = "1.11.0"
22-
stam = "0.18.3"
23-
stam-tools = "0.13.0"
22+
stam = "0.18.6"
23+
stam-tools = "0.14.0"
2424

2525
[features]
2626
default = ["pyo3/extension-module"]

src/annotation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ impl PyAnnotation {
11801180
pub fn get_transpose_config(kwargs: &Bound<PyDict>) -> PyResult<TransposeConfig> {
11811181
let mut config = TransposeConfig::default();
11821182
for (key, value) in kwargs {
1183-
match key.downcast()?.extract()? {
1183+
match key.cast()?.extract()? {
11841184
"debug" => {
11851185
if let Ok(Some(value)) = value.extract() {
11861186
config.debug = value;
@@ -1220,7 +1220,7 @@ pub fn get_transpose_config(kwargs: &Bound<PyDict>) -> PyResult<TransposeConfig>
12201220
pub fn get_translate_config(kwargs: &Bound<PyDict>) -> PyResult<TranslateConfig> {
12211221
let mut config = TranslateConfig::default();
12221222
for (key, value) in kwargs {
1223-
match key.downcast()?.extract()? {
1223+
match key.cast()?.extract()? {
12241224
"debug" => {
12251225
if let Ok(Some(value)) = value.extract() {
12261226
config.debug = value;

src/annotationdata.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ pub(crate) fn datavalue_from_py<'py>(value: Bound<'py, PyAny>) -> Result<DataVal
293293
Ok(DataValue::Datetime(value))
294294
} else {
295295
if value.is_instance_of::<PyList>() {
296-
let value: &Bound<'py, PyList> = value.downcast().expect("downcast must succeed");
296+
let value: &Bound<'py, PyList> = value.cast().expect("cast must succeed");
297297
let mut list: Vec<DataValue> = Vec::new();
298298
for item in value {
299299
let pyitem = datavalue_from_py(item)?;
300300
list.push(pyitem);
301301
}
302302
return Ok(DataValue::List(list));
303303
} else if value.is_instance_of::<PyDict>() {
304-
let value: &Bound<'py, PyDict> = value.downcast().expect("downcast must succeed");
304+
let value: &Bound<'py, PyDict> = value.cast().expect("cast must succeed");
305305
let mut map: BTreeMap<String, DataValue> = BTreeMap::new();
306306
for (key, item) in value.iter() {
307307
let pyitem = datavalue_from_py(item)?;
@@ -639,7 +639,7 @@ pub(crate) fn annotationdata_builder<'py>(
639639
builder = builder.with_dataset(adata.set.into());
640640
Ok(builder)
641641
} else if data.is_instance_of::<PyDict>() {
642-
let data = data.downcast::<PyDict>()?;
642+
let data = data.cast::<PyDict>()?;
643643
if let Ok(Some(id)) = data.get_item("id") {
644644
if id.is_instance_of::<PyAnnotationData>() {
645645
let adata: PyRef<'_, PyAnnotationData> = id.extract()?;
@@ -676,7 +676,7 @@ pub(crate) fn annotationdata_builder<'py>(
676676
}
677677
Ok(builder)
678678
} else if data.is_instance_of::<PyString>() {
679-
let id: String = data.downcast()?.extract()?;
679+
let id: String = data.cast()?.extract()?;
680680
Ok(AnnotationDataBuilder::new().with_id(id.into()))
681681
} else {
682682
Err(PyValueError::new_err(
@@ -720,7 +720,7 @@ pub(crate) fn dataoperator_from_kwargs<'py>(
720720
))))
721721
} else if let Ok(Some(values)) = kwargs.get_item("value_in") {
722722
if values.is_instance_of::<PyTuple>() {
723-
let values: &Bound<'py, PyTuple> = values.downcast().unwrap();
723+
let values: &Bound<'py, PyTuple> = values.cast().unwrap();
724724
let mut suboperators = Vec::with_capacity(values.len());
725725
for value in values {
726726
suboperators.push(dataoperator_from_py(value)?)
@@ -731,7 +731,7 @@ pub(crate) fn dataoperator_from_kwargs<'py>(
731731
}
732732
} else if let Ok(Some(values)) = kwargs.get_item("value_not_in") {
733733
if values.is_instance_of::<PyTuple>() {
734-
let values: &Bound<'py, PyTuple> = values.downcast().unwrap();
734+
let values: &Bound<'py, PyTuple> = values.cast().unwrap();
735735
let mut suboperators = Vec::with_capacity(values.len());
736736
for value in values {
737737
suboperators.push(dataoperator_from_py(value)?)

src/annotationstore.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use pyo3::exceptions::{PyRuntimeError, PyTypeError, PyValueError};
22
use pyo3::prelude::*;
3+
use pyo3::pyclass::PyClassGuardError;
34
use pyo3::types::*;
45
use rayon::iter::{IntoParallelIterator, ParallelIterator};
56
use std::ops::FnOnce;
@@ -45,7 +46,7 @@ impl PyAnnotationStore {
4546
if let Some(kwargs) = kwargs {
4647
let mut config = PyDict::new(py);
4748
for (key, value) in kwargs.iter() {
48-
match key.downcast()?.extract()? {
49+
match key.cast()?.extract()? {
4950
"config" => {
5051
if let Ok(Some(value)) = value.extract() {
5152
config = value;
@@ -55,10 +56,10 @@ impl PyAnnotationStore {
5556
}
5657
}
5758
for (key, value) in kwargs.iter() {
58-
match key.downcast()?.extract()? {
59+
match key.cast()?.extract()? {
5960
"config" => continue, //already handled
6061
"file" => {
61-
let value = value.downcast()?.extract()?;
62+
let value = value.cast()?.extract()?;
6263
return match AnnotationStore::from_file(value, get_config(&config)?) {
6364
Ok(store) => Ok(PyAnnotationStore {
6465
store: Arc::new(RwLock::new(store)),
@@ -67,7 +68,7 @@ impl PyAnnotationStore {
6768
};
6869
}
6970
"string" => {
70-
let value = value.downcast()?.extract()?;
71+
let value = value.cast()?.extract()?;
7172
return match AnnotationStore::from_str(value, get_config(&config)?) {
7273
Ok(store) => Ok(PyAnnotationStore {
7374
store: Arc::new(RwLock::new(store)),
@@ -76,7 +77,7 @@ impl PyAnnotationStore {
7677
};
7778
}
7879
"id" => {
79-
let value: String = value.downcast()?.extract()?;
80+
let value: String = value.cast()?.extract()?;
8081
return Ok(PyAnnotationStore {
8182
store: Arc::new(RwLock::new(
8283
AnnotationStore::default()
@@ -284,7 +285,7 @@ impl PyAnnotationStore {
284285
}
285286
builder = builder.with_target(target.build());
286287
if data.is_instance_of::<PyList>() {
287-
let data: Bound<'py, PyList> = data.downcast()?.clone();
288+
let data: Bound<'py, PyList> = data.cast()?.clone();
288289
for databuilder in data.iter() {
289290
let databuilder = annotationdata_builder(databuilder)?;
290291
builder = builder.with_data_builder(databuilder);
@@ -420,51 +421,51 @@ impl PyAnnotationStore {
420421
if let Some(kwargs) = kwargs {
421422
//bind keyword arguments as variables in the query
422423
for (varname, value) in kwargs.iter() {
423-
if let Ok(varname) = varname.downcast::<PyString>() {
424+
if let Ok(varname) = varname.cast::<PyString>() {
424425
if let Ok(varname) = varname.to_str() {
425426
if value.is_instance_of::<PyAnnotation>() {
426427
let annotation: PyResult<PyRef<'py, PyAnnotation>> =
427-
value.extract();
428+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
428429
if let Ok(annotation) = annotation {
429430
let annotation =
430431
store.annotation(annotation.handle).or_fail()?;
431432
query.bind_annotationvar(varname, &annotation);
432433
}
433434
} else if value.is_instance_of::<PyAnnotationData>() {
434435
let data: PyResult<PyRef<'py, PyAnnotationData>> =
435-
value.extract();
436+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
436437
if let Ok(data) = data {
437438
let data =
438439
store.annotationdata(data.set, data.handle).or_fail()?;
439440
query.bind_datavar(varname, &data);
440441
}
441442
} else if value.is_instance_of::<PyDataKey>() {
442443
let key: PyResult<PyRef<'py, PyDataKey>> =
443-
value.extract();
444+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
444445
if let Ok(key) = key {
445446
let key =
446447
store.key(key.set, key.handle).or_fail()?;
447448
query.bind_keyvar(varname, &key);
448449
}
449450
} else if value.is_instance_of::<PyTextResource>() {
450451
let resource: PyResult<PyRef<'py, PyTextResource>> =
451-
value.extract();
452+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
452453
if let Ok(resource) = resource {
453454
let resource =
454455
store.resource(resource.handle).or_fail()?;
455456
query.bind_resourcevar(varname, &resource);
456457
}
457458
} else if value.is_instance_of::<PyAnnotationDataSet>() {
458459
let dataset: PyResult<PyRef<'py, PyAnnotationDataSet>> =
459-
value.extract();
460+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
460461
if let Ok(dataset) = dataset {
461462
let dataset =
462463
store.dataset(dataset.handle).or_fail()?;
463464
query.bind_datasetvar(varname, &dataset);
464465
}
465466
} else if value.is_instance_of::<PyTextSelection>() {
466467
let textselection: PyResult<PyRef<'py, PyTextSelection>> =
467-
value.extract();
468+
value.extract().map_err(|e: PyClassGuardError<'_, 'py>| e.into());
468469
if let Ok(textselection) = textselection {
469470
if let Some(handle) = textselection.textselection.handle() {
470471
if let Some(textselection) =

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use stamtools::align::{AbsoluteOrRelative, AlignmentAlgorithm, AlignmentConfig};
88
pub fn get_config<'py>(kwargs: &Bound<'py, PyDict>) -> PyResult<Config> {
99
let mut config = Config::default();
1010
for (key, value) in kwargs {
11-
match key.downcast()?.extract()? {
11+
match key.cast()?.extract()? {
1212
"use_include" => {
1313
if let Ok(Some(value)) = value.extract() {
1414
config = config.with_use_include(value);

src/query.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
'context: 'store,
3939
{
4040
if filter.is_instance_of::<PyDict>() {
41-
let filter = filter.downcast()?;
41+
let filter = filter.cast()?;
4242
let operator = dataoperator_from_kwargs(&filter)
4343
.map_err(|err| PyValueError::new_err(format!("{}", err)))?
4444
.or(operator);
@@ -92,7 +92,7 @@ where
9292
}
9393
} else if filter.contains("set")? {
9494
if key.is_instance_of::<PyString>() {
95-
let key = key.downcast::<PyString>()?;
95+
let key = key.cast::<PyString>()?;
9696
let set = filter.get_item("set")?.expect("already checked");
9797
let key = if set.is_instance_of::<PyAnnotationDataSet>() {
9898
let set: PyRef<'py, PyAnnotationDataSet> = filter.extract()?;
@@ -110,7 +110,7 @@ where
110110
));
111111
}
112112
} else if set.is_instance_of::<PyString>() {
113-
let set = set.downcast::<PyString>()?;
113+
let set = set.cast::<PyString>()?;
114114
if let Some(dataset) = store.dataset(set.to_str()?) {
115115
if let Some(key) = dataset.key(key.to_str()?) {
116116
Some(key)
@@ -317,7 +317,7 @@ where
317317
} else if let Ok(Some(filter)) = kwargs.get_item("filters") {
318318
//backwards compatibility
319319
if filter.is_instance_of::<PyList>() {
320-
let vec = filter.downcast::<PyList>()?;
320+
let vec = filter.cast::<PyList>()?;
321321
for filter in vec {
322322
used_contextvarnames = add_filter(
323323
&mut query,
@@ -328,7 +328,7 @@ where
328328
)?;
329329
}
330330
} else if filter.is_instance_of::<PyTuple>() {
331-
let vec = filter.downcast::<PyTuple>()?;
331+
let vec = filter.cast::<PyTuple>()?;
332332
for filter in vec {
333333
used_contextvarnames = add_filter(
334334
&mut query,
@@ -364,8 +364,8 @@ pub(crate) fn has_filters<'py>(
364364
for key in kwargs.keys() {
365365
if key.is_instance_of::<PyString>() {
366366
let key: &str = key
367-
.downcast()
368-
.expect("downcast must work")
367+
.cast()
368+
.expect("cast must work")
369369
.extract()
370370
.expect("extract must work");
371371
if let "limit" | "recursive" | "substore" = key {

0 commit comments

Comments
 (0)