deps: upgrade PyO3 to 0.21 (#275)

master
Caleb Hattingh 2024-05-07 16:36:46 +02:00 committed by GitHub
parent 14827d94d2
commit cc7e785cba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 96 additions and 68 deletions

View File

@ -42,15 +42,20 @@ jobs:
run: cargo fmt --check run: cargo fmt --check
Test: Test:
continue-on-error: ${{ matrix.python-version == '3.13' }}
env:
UNSAFE_PYO3_SKIP_VERSION_CHECK: ${{ matrix.unsafe-pyo3-skip-version-check }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.12"] python-version: ["3.12"]
allow-prereleases: [false] allow-prereleases: [false]
unsafe-pyo3-skip-version-check: [0]
include: include:
- os: ubuntu-latest - os: ubuntu-latest
python-version: "3.13" python-version: "3.13"
allow-prereleases: true allow-prereleases: true
unsafe-pyo3-skip-version-check: 1
- os: ubuntu-latest - os: ubuntu-latest
python-version: "3.11" python-version: "3.11"
allow-prereleases: false allow-prereleases: false

32
Cargo.lock generated
View File

@ -722,6 +722,12 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "portable-atomic"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
version = "0.2.0" version = "0.2.0"
@ -745,9 +751,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3" name = "pyo3"
version = "0.20.0" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04e8453b658fe480c3e70c8ed4e3d3ec33eb74988bd186561b0cc66b85c3bc4b" checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"chrono", "chrono",
@ -755,6 +761,7 @@ dependencies = [
"libc", "libc",
"memoffset", "memoffset",
"parking_lot", "parking_lot",
"portable-atomic",
"pyo3-build-config", "pyo3-build-config",
"pyo3-ffi", "pyo3-ffi",
"pyo3-macros", "pyo3-macros",
@ -763,9 +770,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-build-config" name = "pyo3-build-config"
version = "0.20.0" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a96fe70b176a89cff78f2fa7b3c930081e163d5379b4dcdf993e3ae29ca662e5" checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"target-lexicon", "target-lexicon",
@ -773,9 +780,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-ffi" name = "pyo3-ffi"
version = "0.20.0" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "214929900fd25e6604661ed9cf349727c8920d47deff196c4e28165a6ef2a96b" checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403"
dependencies = [ dependencies = [
"libc", "libc",
"pyo3-build-config", "pyo3-build-config",
@ -783,9 +790,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros" name = "pyo3-macros"
version = "0.20.0" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac53072f717aa1bfa4db832b39de8c875b7c7af4f4a6fe93cdbf9264cf8383b" checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"pyo3-macros-backend", "pyo3-macros-backend",
@ -795,21 +802,22 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros-backend" name = "pyo3-macros-backend"
version = "0.20.0" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7774b5a8282bd4f25f803b1f0d945120be959a36c72e08e7cd031c792fdfd424" checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"pyo3-build-config",
"quote", "quote",
"syn", "syn",
] ]
[[package]] [[package]]
name = "pythonize" name = "pythonize"
version = "0.20.0" version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffd1c3ef39c725d63db5f9bc455461bafd80540cb7824c61afb823501921a850" checksum = "9d0664248812c38cc55a4ed07f88e4df516ce82604b93b1ffdc041aa77a6cb3c"
dependencies = [ dependencies = [
"pyo3", "pyo3",
"serde", "serde",

View File

@ -11,7 +11,7 @@ name = "tantivy"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[build-dependencies] [build-dependencies]
pyo3-build-config = "0.20.0" pyo3-build-config = "0.21.0"
[dependencies] [dependencies]
base64 = "0.22" base64 = "0.22"
@ -19,10 +19,10 @@ chrono = "0.4.38"
tantivy = "0.22.0" tantivy = "0.22.0"
itertools = "0.12.1" itertools = "0.12.1"
futures = "0.3.30" futures = "0.3.30"
pythonize = "0.20.0" pythonize = "0.21.0"
serde = "1.0" serde = "1.0"
serde_json = "1.0.116" serde_json = "1.0.116"
[dependencies.pyo3] [dependencies.pyo3]
version = "0.20.0" version = "0.21.0"
features = ["chrono", "extension-module"] features = ["chrono", "extension-module"]

View File

@ -27,7 +27,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> { pub(crate) fn extract_value(any: &Bound<PyAny>) -> PyResult<Value> {
if let Ok(s) = any.extract::<String>() { if let Ok(s) = any.extract::<String>() {
return Ok(Value::Str(s)); return Ok(Value::Str(s));
} }
@ -42,7 +42,7 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
} }
if let Ok(datetime) = any.extract::<NaiveDateTime>() { if let Ok(datetime) = any.extract::<NaiveDateTime>() {
return Ok(Value::Date(tv::DateTime::from_timestamp_secs( return Ok(Value::Date(tv::DateTime::from_timestamp_secs(
datetime.timestamp(), datetime.and_utc().timestamp(),
))); )));
} }
if let Ok(facet) = any.extract::<Facet>() { if let Ok(facet) = any.extract::<Facet>() {
@ -52,7 +52,8 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
return Ok(Value::Bytes(b)); return Ok(Value::Bytes(b));
} }
if let Ok(dict) = any.downcast::<PyDict>() { if let Ok(dict) = any.downcast::<PyDict>() {
if let Ok(json) = pythonize::depythonize(dict) { if let Ok(json) = pythonize::depythonize_bound(dict.clone().into_any())
{
return Ok(Value::Object(json)); return Ok(Value::Object(json));
} }
} }
@ -60,7 +61,7 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
} }
pub(crate) fn extract_value_for_type( pub(crate) fn extract_value_for_type(
any: &PyAny, any: &Bound<PyAny>,
tv_type: tv::schema::Type, tv_type: tv::schema::Type,
field_name: &str, field_name: &str,
) -> PyResult<Value> { ) -> PyResult<Value> {
@ -68,7 +69,7 @@ pub(crate) fn extract_value_for_type(
fn to_pyerr_for_type<'a, E: std::error::Error>( fn to_pyerr_for_type<'a, E: std::error::Error>(
type_name: &'a str, type_name: &'a str,
field_name: &'a str, field_name: &'a str,
any: &'a PyAny, any: &'a Bound<PyAny>,
) -> impl Fn(E) -> PyErr + 'a { ) -> impl Fn(E) -> PyErr + 'a {
move |_| { move |_| {
to_pyerr(format!( to_pyerr(format!(
@ -104,7 +105,9 @@ pub(crate) fn extract_value_for_type(
.extract::<NaiveDateTime>() .extract::<NaiveDateTime>()
.map_err(to_pyerr_for_type("DateTime", field_name, any))?; .map_err(to_pyerr_for_type("DateTime", field_name, any))?;
Value::Date(tv::DateTime::from_timestamp_secs(datetime.timestamp())) Value::Date(tv::DateTime::from_timestamp_secs(
datetime.and_utc().timestamp(),
))
} }
tv::schema::Type::Facet => Value::Facet( tv::schema::Type::Facet => Value::Facet(
any.extract::<Facet>() any.extract::<Facet>()
@ -124,9 +127,11 @@ pub(crate) fn extract_value_for_type(
Value::Object( Value::Object(
any.downcast::<PyDict>() any.downcast::<PyDict>()
.map(|dict| pythonize::depythonize(dict)) .map_err(to_pyerr_for_type("Json", field_name, any))
.map_err(to_pyerr_for_type("Json", field_name, any))? .and_then(|dict| {
.map_err(to_pyerr_for_type("Json", field_name, any))?, pythonize::depythonize_bound(dict.clone().into_any())
.map_err(to_pyerr_for_type("Json", field_name, any))
})?,
) )
} }
tv::schema::Type::IpAddr => { tv::schema::Type::IpAddr => {
@ -147,16 +152,16 @@ pub(crate) fn extract_value_for_type(
Ok(value) Ok(value)
} }
fn extract_value_single_or_list(any: &PyAny) -> PyResult<Vec<Value>> { fn extract_value_single_or_list(any: &Bound<PyAny>) -> PyResult<Vec<Value>> {
if let Ok(values) = any.downcast::<PyList>() { if let Ok(values) = any.downcast::<PyList>() {
values.iter().map(extract_value).collect() values.iter().map(|v| extract_value(&v)).collect()
} else { } else {
Ok(vec![extract_value(any)?]) Ok(vec![extract_value(any)?])
} }
} }
fn extract_value_single_or_list_for_type( fn extract_value_single_or_list_for_type(
any: &PyAny, any: &Bound<PyAny>,
field_type: &tv::schema::FieldType, field_type: &tv::schema::FieldType,
field_name: &str, field_name: &str,
) -> PyResult<Vec<Value>> { ) -> PyResult<Vec<Value>> {
@ -179,7 +184,11 @@ fn extract_value_single_or_list_for_type(
values values
.iter() .iter()
.map(|any| { .map(|any| {
extract_value_for_type(any, field_type.value_type(), field_name) extract_value_for_type(
&any,
field_type.value_type(),
field_name,
)
}) })
.collect() .collect()
} else { } else {
@ -195,7 +204,7 @@ fn object_to_py(
py: Python, py: Python,
obj: &BTreeMap<String, Value>, obj: &BTreeMap<String, Value>,
) -> PyResult<PyObject> { ) -> PyResult<PyObject> {
let dict = PyDict::new(py); let dict = PyDict::new_bound(py);
for (k, v) in obj.iter() { for (k, v) in obj.iter() {
dict.set_item(k, value_to_py(py, v)?)?; dict.set_item(k, value_to_py(py, v)?)?;
} }
@ -216,7 +225,7 @@ fn value_to_py(py: Python, value: &Value) -> PyResult<PyObject> {
} }
Value::Date(d) => { Value::Date(d) => {
let utc = d.into_utc(); let utc = d.into_utc();
PyDateTime::new( PyDateTime::new_bound(
py, py,
utc.year(), utc.year(),
utc.month() as u8, utc.month() as u8,
@ -538,7 +547,7 @@ impl Document {
/// [`extend()`], or `add_<type>()` functions. /// [`extend()`], or `add_<type>()` functions.
#[new] #[new]
#[pyo3(signature = (**kwargs))] #[pyo3(signature = (**kwargs))]
fn new(kwargs: Option<&PyDict>) -> PyResult<Self> { fn new(kwargs: Option<&Bound<PyDict>>) -> PyResult<Self> {
let mut document = Document::default(); let mut document = Document::default();
if let Some(field_dict) = kwargs { if let Some(field_dict) = kwargs {
document.extend(field_dict, None)?; document.extend(field_dict, None)?;
@ -548,7 +557,7 @@ impl Document {
fn extend( fn extend(
&mut self, &mut self,
py_dict: &PyDict, py_dict: &Bound<PyDict>,
schema: Option<&Schema>, schema: Option<&Schema>,
) -> PyResult<()> { ) -> PyResult<()> {
Document::extract_py_values_from_dict( Document::extract_py_values_from_dict(
@ -560,7 +569,7 @@ impl Document {
#[staticmethod] #[staticmethod]
fn from_dict( fn from_dict(
py_dict: &PyDict, py_dict: &Bound<PyDict>,
schema: Option<&Schema>, schema: Option<&Schema>,
) -> PyResult<Document> { ) -> PyResult<Document> {
let mut field_values: BTreeMap<String, Vec<Value>> = BTreeMap::new(); let mut field_values: BTreeMap<String, Vec<Value>> = BTreeMap::new();
@ -581,7 +590,7 @@ impl Document {
/// For this reason, the dictionary, will associate /// For this reason, the dictionary, will associate
/// a list of value for every field. /// a list of value for every field.
fn to_dict(&self, py: Python) -> PyResult<PyObject> { fn to_dict(&self, py: Python) -> PyResult<PyObject> {
let dict = PyDict::new(py); let dict = PyDict::new_bound(py);
for (key, values) in &self.field_values { for (key, values) in &self.field_values {
let values_py: Vec<PyObject> = values let values_py: Vec<PyObject> = values
.iter() .iter()
@ -642,7 +651,7 @@ impl Document {
/// Args: /// Args:
/// field_name (str): The field name for which we are adding the date. /// field_name (str): The field name for which we are adding the date.
/// value (datetime): The date that will be added to the document. /// value (datetime): The date that will be added to the document.
fn add_date(&mut self, field_name: String, value: &PyDateTime) { fn add_date(&mut self, field_name: String, value: &Bound<PyDateTime>) {
let datetime = Utc let datetime = Utc
.with_ymd_and_hms( .with_ymd_and_hms(
value.get_year(), value.get_year(),
@ -685,7 +694,11 @@ impl Document {
/// to the document. /// to the document.
/// ///
/// Raises a ValueError if the JSON is invalid. /// Raises a ValueError if the JSON is invalid.
fn add_json(&mut self, field_name: String, value: &PyAny) -> PyResult<()> { fn add_json(
&mut self,
field_name: String,
value: &Bound<PyAny>,
) -> PyResult<()> {
type JsonMap = serde_json::Map<String, serde_json::Value>; type JsonMap = serde_json::Map<String, serde_json::Value>;
if let Ok(json_str) = value.extract::<&str>() { if let Ok(json_str) = value.extract::<&str>() {
@ -693,7 +706,9 @@ impl Document {
serde_json::from_str(json_str).map_err(to_pyerr)?; serde_json::from_str(json_str).map_err(to_pyerr)?;
self.add_value(field_name, json_map); self.add_value(field_name, json_map);
Ok(()) Ok(())
} else if let Ok(json_map) = pythonize::depythonize::<JsonMap>(value) { } else if let Ok(json_map) =
pythonize::depythonize_bound::<JsonMap>(value.clone())
{
self.add_value(field_name, json_map); self.add_value(field_name, json_map);
Ok(()) Ok(())
} else { } else {
@ -760,7 +775,7 @@ impl Document {
self.clone() self.clone()
} }
fn __deepcopy__(&self, _memo: &PyDict) -> Self { fn __deepcopy__(&self, _memo: &Bound<PyDict>) -> Self {
self.clone() self.clone()
} }
@ -778,21 +793,21 @@ impl Document {
} }
#[staticmethod] #[staticmethod]
fn _internal_from_pythonized(serialized: &PyAny) -> PyResult<Self> { fn _internal_from_pythonized(serialized: &Bound<PyAny>) -> PyResult<Self> {
pythonize::depythonize(serialized).map_err(to_pyerr) pythonize::depythonize_bound(serialized.clone()).map_err(to_pyerr)
} }
fn __reduce__<'a>( fn __reduce__<'a>(
slf: PyRef<'a, Self>, slf: PyRef<'a, Self>,
py: Python<'a>, py: Python<'a>,
) -> PyResult<&'a PyTuple> { ) -> PyResult<Bound<'a, PyTuple>> {
let serialized = pythonize::pythonize(py, &*slf).map_err(to_pyerr)?; let serialized = pythonize::pythonize(py, &*slf).map_err(to_pyerr)?;
Ok(PyTuple::new( Ok(PyTuple::new_bound(
py, py,
[ [
slf.into_py(py).getattr(py, "_internal_from_pythonized")?, slf.into_py(py).getattr(py, "_internal_from_pythonized")?,
PyTuple::new(py, [serialized]).to_object(py), PyTuple::new_bound(py, [serialized]).to_object(py),
], ],
)) ))
} }
@ -810,7 +825,7 @@ impl Document {
} }
fn extract_py_values_from_dict( fn extract_py_values_from_dict(
py_dict: &PyDict, py_dict: &Bound<PyDict>,
schema: Option<&Schema>, schema: Option<&Schema>,
out_field_values: &mut BTreeMap<String, Vec<Value>>, out_field_values: &mut BTreeMap<String, Vec<Value>>,
) -> PyResult<()> { ) -> PyResult<()> {
@ -847,12 +862,12 @@ impl Document {
let value_list = if let Some(field_type) = field_type { let value_list = if let Some(field_type) = field_type {
extract_value_single_or_list_for_type( extract_value_single_or_list_for_type(
key_value.get_item(1)?, &key_value.get_item(1)?,
field_type, field_type,
key.as_str(), key.as_str(),
)? )?
} else { } else {
extract_value_single_or_list(key_value.get_item(1)?)? extract_value_single_or_list(&key_value.get_item(1)?)?
}; };
out_field_values.insert(key, value_list); out_field_values.insert(key, value_list);

View File

@ -34,7 +34,7 @@ impl Facet {
/// Create a new instance of the "root facet" Equivalent to /. /// Create a new instance of the "root facet" Equivalent to /.
#[classmethod] #[classmethod]
fn root(_cls: &PyType) -> Facet { fn root(_cls: &Bound<PyType>) -> Facet {
Facet { Facet {
inner: schema::Facet::root(), inner: schema::Facet::root(),
} }
@ -60,7 +60,7 @@ impl Facet {
/// ///
/// Returns the created Facet. /// Returns the created Facet.
#[classmethod] #[classmethod]
fn from_string(_cls: &PyType, facet_string: &str) -> Facet { fn from_string(_cls: &Bound<PyType>, facet_string: &str) -> Facet {
Facet { Facet {
inner: schema::Facet::from(facet_string), inner: schema::Facet::from(facet_string),
} }
@ -98,13 +98,13 @@ impl Facet {
fn __reduce__<'a>( fn __reduce__<'a>(
slf: PyRef<'a, Self>, slf: PyRef<'a, Self>,
py: Python<'a>, py: Python<'a>,
) -> PyResult<&'a PyTuple> { ) -> PyResult<Bound<'a, PyTuple>> {
let encoded_bytes = slf.inner.encoded_str().as_bytes().to_vec(); let encoded_bytes = slf.inner.encoded_str().as_bytes().to_vec();
Ok(PyTuple::new( Ok(PyTuple::new_bound(
py, py,
[ [
slf.into_py(py).getattr(py, "from_encoded")?, slf.into_py(py).getattr(py, "from_encoded")?,
PyTuple::new(py, [encoded_bytes]).to_object(py), PyTuple::new_bound(py, [encoded_bytes]).to_object(py),
], ],
)) ))
} }

View File

@ -154,7 +154,7 @@ impl IndexWriter {
fn delete_documents( fn delete_documents(
&mut self, &mut self,
field_name: &str, field_name: &str,
field_value: &PyAny, field_value: &Bound<PyAny>,
) -> PyResult<u64> { ) -> PyResult<u64> {
let field = get_field(&self.schema, field_name)?; let field = get_field(&self.schema, field_name)?;
let value = extract_value(field_value)?; let value = extract_value(field_value)?;

View File

@ -74,7 +74,7 @@ use crate::document::extract_value;
/// >>> assert len(result) == 1 /// >>> assert len(result) == 1
/// ///
#[pymodule] #[pymodule]
fn tantivy(_py: Python, m: &PyModule) -> PyResult<()> { fn tantivy(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<Order>()?; m.add_class::<Order>()?;
m.add_class::<Schema>()?; m.add_class::<Schema>()?;
m.add_class::<SchemaBuilder>()?; m.add_class::<SchemaBuilder>()?;
@ -119,7 +119,7 @@ fn tantivy(_py: Python, m: &PyModule) -> PyResult<()> {
/// >>> assert isinstance(errors[0], query_parser_error.FieldDoesNotExistError) /// >>> assert isinstance(errors[0], query_parser_error.FieldDoesNotExistError)
/// >>> assert isinstance(errors[1], query_parser_error.ExpectedIntError) /// >>> assert isinstance(errors[1], query_parser_error.ExpectedIntError)
#[pymodule] #[pymodule]
fn query_parser_error(_py: Python, m: &PyModule) -> PyResult<()> { fn query_parser_error(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<parser_error::SyntaxError>()?; m.add_class::<parser_error::SyntaxError>()?;
m.add_class::<parser_error::UnsupportedQueryError>()?; m.add_class::<parser_error::UnsupportedQueryError>()?;
m.add_class::<parser_error::FieldDoesNotExistError>()?; m.add_class::<parser_error::FieldDoesNotExistError>()?;
@ -161,7 +161,7 @@ pub(crate) fn get_field(
pub(crate) fn make_term( pub(crate) fn make_term(
schema: &tv::schema::Schema, schema: &tv::schema::Schema,
field_name: &str, field_name: &str,
field_value: &PyAny, field_value: &Bound<PyAny>,
) -> PyResult<tv::Term> { ) -> PyResult<tv::Term> {
let field = get_field(schema, field_name)?; let field = get_field(schema, field_name)?;
let value = extract_value(field_value)?; let value = extract_value(field_value)?;

View File

@ -71,7 +71,7 @@ impl Query {
pub(crate) fn term_query( pub(crate) fn term_query(
schema: &Schema, schema: &Schema,
field_name: &str, field_name: &str,
field_value: &PyAny, field_value: &Bound<PyAny>,
index_option: &str, index_option: &str,
) -> PyResult<Query> { ) -> PyResult<Query> {
let term = make_term(&schema.inner, field_name, field_value)?; let term = make_term(&schema.inner, field_name, field_value)?;
@ -95,12 +95,12 @@ impl Query {
pub(crate) fn term_set_query( pub(crate) fn term_set_query(
schema: &Schema, schema: &Schema,
field_name: &str, field_name: &str,
field_values: Vec<&PyAny>, field_values: Vec<Bound<PyAny>>,
) -> PyResult<Query> { ) -> PyResult<Query> {
let terms = field_values let terms = field_values
.into_iter() .into_iter()
.map(|field_value| { .map(|field_value| {
make_term(&schema.inner, field_name, field_value) make_term(&schema.inner, field_name, &field_value)
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
let inner = tv::query::TermSetQuery::new(terms); let inner = tv::query::TermSetQuery::new(terms);
@ -133,7 +133,7 @@ impl Query {
pub(crate) fn fuzzy_term_query( pub(crate) fn fuzzy_term_query(
schema: &Schema, schema: &Schema,
field_name: &str, field_name: &str,
text: &PyString, text: &Bound<PyString>,
distance: u8, distance: u8,
transposition_cost_one: bool, transposition_cost_one: bool,
prefix: bool, prefix: bool,
@ -170,18 +170,18 @@ impl Query {
pub(crate) fn phrase_query( pub(crate) fn phrase_query(
schema: &Schema, schema: &Schema,
field_name: &str, field_name: &str,
words: Vec<&PyAny>, words: Vec<Bound<PyAny>>,
slop: u32, slop: u32,
) -> PyResult<Query> { ) -> PyResult<Query> {
let mut terms_with_offset = Vec::with_capacity(words.len()); let mut terms_with_offset = Vec::with_capacity(words.len());
for (idx, word) in words.into_iter().enumerate() { for (idx, word) in words.into_iter().enumerate() {
if let Ok((offset, value)) = word.extract() { if let Ok((offset, value)) = word.extract() {
// Custom offset is provided. // Custom offset is provided.
let term = make_term(&schema.inner, field_name, value)?; let term = make_term(&schema.inner, field_name, &value)?;
terms_with_offset.push((offset, term)); terms_with_offset.push((offset, term));
} else { } else {
// Custom offset is not provided. Use the list index as the offset. // Custom offset is not provided. Use the list index as the offset.
let term = make_term(&schema.inner, field_name, word)?; let term = make_term(&schema.inner, field_name, &word)?;
terms_with_offset.push((idx, term)); terms_with_offset.push((idx, term));
}; };
} }
@ -221,7 +221,7 @@ impl Query {
#[staticmethod] #[staticmethod]
pub(crate) fn disjunction_max_query( pub(crate) fn disjunction_max_query(
subqueries: Vec<Query>, subqueries: Vec<Query>,
tie_breaker: Option<&PyFloat>, tie_breaker: Option<Bound<PyFloat>>,
) -> PyResult<Query> { ) -> PyResult<Query> {
let inner_queries: Vec<Box<dyn tv::query::Query>> = subqueries let inner_queries: Vec<Box<dyn tv::query::Query>> = subqueries
.iter() .iter()

View File

@ -29,21 +29,21 @@ impl Schema {
} }
#[staticmethod] #[staticmethod]
fn _internal_from_pythonized(serialized: &PyAny) -> PyResult<Self> { fn _internal_from_pythonized(serialized: &Bound<PyAny>) -> PyResult<Self> {
pythonize::depythonize(serialized).map_err(to_pyerr) pythonize::depythonize_bound(serialized.clone()).map_err(to_pyerr)
} }
fn __reduce__<'a>( fn __reduce__<'a>(
slf: PyRef<'a, Self>, slf: PyRef<'a, Self>,
py: Python<'a>, py: Python<'a>,
) -> PyResult<&'a PyTuple> { ) -> PyResult<Bound<'a, PyTuple>> {
let serialized = pythonize::pythonize(py, &*slf).map_err(to_pyerr)?; let serialized = pythonize::pythonize(py, &*slf).map_err(to_pyerr)?;
Ok(PyTuple::new( Ok(PyTuple::new_bound(
py, py,
[ [
slf.into_py(py).getattr(py, "_internal_from_pythonized")?, slf.into_py(py).getattr(py, "_internal_from_pythonized")?,
PyTuple::new(py, [serialized]).to_object(py), PyTuple::new_bound(py, [serialized]).to_object(py),
], ],
)) ))
} }