diff options
author | Erik Johnston <erikj@element.io> | 2024-05-08 14:30:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 14:30:06 +0100 |
commit | 414ddcd45722be8a4a3f70d4b52c3b81be79118f (patch) | |
tree | c88190f9f3d7c2f9749589ba8c729d19d1e0c7a1 /rust/src/push | |
parent | Note preset behaviour in `autocreate_auto_join_room_preset` docs (#17150) (diff) | |
download | synapse-414ddcd45722be8a4a3f70d4b52c3b81be79118f.tar.xz |
Update PyO3 to 0.21 (#17162)
This version change requires a migration to a new API. See https://pyo3.rs/v0.21.2/migration#from-020-to-021 This will fix the annoying warnings added when using the recent rust nightly: > warning: non-local `impl` definition, they should be avoided as they go against expectation
Diffstat (limited to 'rust/src/push')
-rw-r--r-- | rust/src/push/mod.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index 7dedbf10b6..2a452b69a3 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -66,7 +66,7 @@ use log::warn; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; use pyo3::types::{PyBool, PyList, PyLong, PyString}; -use pythonize::{depythonize, pythonize}; +use pythonize::{depythonize_bound, pythonize}; use serde::de::Error as _; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -78,19 +78,19 @@ pub mod evaluator; pub mod utils; /// Called when registering modules with python. -pub fn register_module(py: Python<'_>, m: &PyModule) -> PyResult<()> { - let child_module = PyModule::new(py, "push")?; +pub fn register_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { + let child_module = PyModule::new_bound(py, "push")?; child_module.add_class::<PushRule>()?; child_module.add_class::<PushRules>()?; child_module.add_class::<FilteredPushRules>()?; child_module.add_class::<PushRuleEvaluator>()?; child_module.add_function(wrap_pyfunction!(get_base_rule_ids, m)?)?; - m.add_submodule(child_module)?; + m.add_submodule(&child_module)?; // We need to manually add the module to sys.modules to make `from // synapse.synapse_rust import push` work. - py.import("sys")? + py.import_bound("sys")? .getattr("modules")? .set_item("synapse.synapse_rust.push", child_module)?; @@ -271,12 +271,12 @@ pub enum SimpleJsonValue { impl<'source> FromPyObject<'source> for SimpleJsonValue { fn extract(ob: &'source PyAny) -> PyResult<Self> { - if let Ok(s) = <PyString as pyo3::PyTryFrom>::try_from(ob) { + if let Ok(s) = ob.downcast::<PyString>() { Ok(SimpleJsonValue::Str(Cow::Owned(s.to_string()))) // A bool *is* an int, ensure we try bool first. - } else if let Ok(b) = <PyBool as pyo3::PyTryFrom>::try_from(ob) { + } else if let Ok(b) = ob.downcast::<PyBool>() { Ok(SimpleJsonValue::Bool(b.extract()?)) - } else if let Ok(i) = <PyLong as pyo3::PyTryFrom>::try_from(ob) { + } else if let Ok(i) = ob.downcast::<PyLong>() { Ok(SimpleJsonValue::Int(i.extract()?)) } else if ob.is_none() { Ok(SimpleJsonValue::Null) @@ -299,7 +299,7 @@ pub enum JsonValue { impl<'source> FromPyObject<'source> for JsonValue { fn extract(ob: &'source PyAny) -> PyResult<Self> { - if let Ok(l) = <PyList as pyo3::PyTryFrom>::try_from(ob) { + if let Ok(l) = ob.downcast::<PyList>() { match l.iter().map(SimpleJsonValue::extract).collect() { Ok(a) => Ok(JsonValue::Array(a)), Err(e) => Err(PyTypeError::new_err(format!( @@ -370,8 +370,8 @@ impl IntoPy<PyObject> for Condition { } impl<'source> FromPyObject<'source> for Condition { - fn extract(ob: &'source PyAny) -> PyResult<Self> { - Ok(depythonize(ob)?) + fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult<Self> { + Ok(depythonize_bound(ob.clone())?) } } |