diff --git a/Cargo.lock b/Cargo.lock index e5ce9325df..0edfef6869 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -813,9 +813,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.26.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383" +checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d" dependencies = [ "anyhow", "indoc", @@ -831,18 +831,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.26.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f" +checksum = "b455933107de8642b4487ed26d912c2d899dec6114884214a0b3bb3be9261ea6" dependencies = [ "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.26.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105" +checksum = "1c85c9cbfaddf651b1221594209aed57e9e5cff63c4d11d1feead529b872a089" dependencies = [ "libc", "pyo3-build-config", @@ -861,9 +861,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.26.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded" +checksum = "0a5b10c9bf9888125d917fb4d2ca2d25c8df94c7ab5a52e13313a07e050a3b02" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -873,9 +873,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.26.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf" +checksum = "03b51720d314836e53327f5871d4c0cfb4fb37cc2c4a11cc71907a86342c40f9" dependencies = [ "heck", "proc-macro2", @@ -886,9 +886,9 @@ dependencies = [ [[package]] name = "pythonize" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11e06e4cff9be2bbf2bddf28a486ae619172ea57e79787f856572878c62dcfe2" +checksum = "a3a8f29db331e28c332c63496cfcbb822aca3d7320bc08b655d7fd0c29c50ede" dependencies = [ "pyo3", "serde", diff --git a/changelog.d/19412.misc b/changelog.d/19412.misc new file mode 100644 index 0000000000..6b811be799 --- /dev/null +++ b/changelog.d/19412.misc @@ -0,0 +1 @@ +Bump `pyo3` from 0.26.0 to 0.27.2 and `pythonize` from 0.26.0 to 0.27.0. Contributed by @razvp @ ERCOM. \ No newline at end of file diff --git a/rust/Cargo.toml b/rust/Cargo.toml index e8321d159b..350701d327 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -30,14 +30,14 @@ http = "1.1.0" lazy_static = "1.4.0" log = "0.4.17" mime = "0.3.17" -pyo3 = { version = "0.26.0", features = [ +pyo3 = { version = "0.27.2", features = [ "macros", "anyhow", "abi3", "abi3-py310", ] } pyo3-log = "0.13.1" -pythonize = "0.26.0" +pythonize = "0.27.0" regex = "1.6.0" sha2 = "0.10.8" serde = { version = "1.0.144", features = ["derive"] } diff --git a/rust/src/http.rs b/rust/src/http.rs index 63ed05be54..8d462f2e5e 100644 --- a/rust/src/http.rs +++ b/rust/src/http.rs @@ -32,7 +32,7 @@ fn read_io_body(body: &Bound<'_, PyAny>, chunk_size: usize) -> PyResult { let mut buf = BytesMut::new(); loop { let bound = &body.call_method1("read", (chunk_size,))?; - let bytes: &Bound<'_, PyBytes> = bound.downcast()?; + let bytes: &Bound<'_, PyBytes> = bound.cast()?; if bytes.as_bytes().is_empty() { return Ok(buf.into()); } @@ -58,12 +58,12 @@ pub fn http_request_from_twisted(request: &Bound<'_, PyAny>) -> PyResult = bound.downcast()?; + let uri: &Bound<'_, PyBytes> = bound.cast()?; *req.uri_mut() = Uri::try_from(uri.as_bytes()).map_err(|_| PyValueError::new_err("invalid uri"))?; let bound = &request.getattr("method")?; - let method: &Bound<'_, PyBytes> = bound.downcast()?; + let method: &Bound<'_, PyBytes> = bound.cast()?; *req.method_mut() = Method::from_bytes(method.as_bytes()) .map_err(|_| PyValueError::new_err("invalid method"))?; @@ -74,17 +74,17 @@ pub fn http_request_from_twisted(request: &Bound<'_, PyAny>) -> PyResult = header.downcast()?; + let header: &Bound<'_, PyTuple> = header.cast()?; let bound = &header.get_item(0)?; - let name: &Bound<'_, PyBytes> = bound.downcast()?; + let name: &Bound<'_, PyBytes> = bound.cast()?; let name = HeaderName::from_bytes(name.as_bytes()) .map_err(|_| PyValueError::new_err("invalid header name"))?; let bound = &header.get_item(1)?; - let values: &Bound<'_, PySequence> = bound.downcast()?; + let values: &Bound<'_, PySequence> = bound.cast()?; for index in 0..values.len()? { let bound = &values.get_item(index)?; - let value: &Bound<'_, PyBytes> = bound.downcast()?; + let value: &Bound<'_, PyBytes> = bound.cast()?; let value = HeaderValue::from_bytes(value.as_bytes()) .map_err(|_| PyValueError::new_err("invalid header value"))?; req.headers_mut().append(name.clone(), value); diff --git a/rust/src/http_client.rs b/rust/src/http_client.rs index 4bd80c8e04..b1e4f753b8 100644 --- a/rust/src/http_client.rs +++ b/rust/src/http_client.rs @@ -316,5 +316,8 @@ fn make_deferred_yieldable<'py>( func }); - make_deferred_yieldable.call1(py, (deferred,))?.extract(py) + make_deferred_yieldable + .call1(py, (deferred,))? + .extract(py) + .map_err(Into::into) } diff --git a/rust/src/push/mod.rs b/rust/src/push/mod.rs index b0cedd758c..ac9b9c93e4 100644 --- a/rust/src/push/mod.rs +++ b/rust/src/push/mod.rs @@ -273,14 +273,16 @@ pub enum SimpleJsonValue { Null, } -impl<'source> FromPyObject<'source> for SimpleJsonValue { - fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult { - if let Ok(s) = ob.downcast::() { +impl<'source> FromPyObject<'_, 'source> for SimpleJsonValue { + type Error = PyErr; + + fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result { + if let Ok(s) = ob.cast::() { Ok(SimpleJsonValue::Str(Cow::Owned(s.to_string()))) // A bool *is* an int, ensure we try bool first. - } else if let Ok(b) = ob.downcast::() { + } else if let Ok(b) = ob.cast::() { Ok(SimpleJsonValue::Bool(b.extract()?)) - } else if let Ok(i) = ob.downcast::() { + } else if let Ok(i) = ob.cast::() { Ok(SimpleJsonValue::Int(i.extract()?)) } else if ob.is_none() { Ok(SimpleJsonValue::Null) @@ -301,12 +303,14 @@ pub enum JsonValue { Value(SimpleJsonValue), } -impl<'source> FromPyObject<'source> for JsonValue { - fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult { - if let Ok(l) = ob.downcast::() { +impl<'source> FromPyObject<'_, 'source> for JsonValue { + type Error = PyErr; + + fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result { + if let Ok(l) = ob.cast::() { match l .iter() - .map(|it| SimpleJsonValue::extract_bound(&it)) + .map(|it| SimpleJsonValue::extract(it.as_borrowed())) .collect() { Ok(a) => Ok(JsonValue::Array(a)), @@ -314,7 +318,7 @@ impl<'source> FromPyObject<'source> for JsonValue { "Can't convert to JsonValue::Array: {e}" ))), } - } else if let Ok(v) = SimpleJsonValue::extract_bound(ob) { + } else if let Ok(v) = SimpleJsonValue::extract(ob) { Ok(JsonValue::Value(v)) } else { Err(PyTypeError::new_err(format!( @@ -385,9 +389,11 @@ impl<'source> IntoPyObject<'source> for Condition { } } -impl<'source> FromPyObject<'source> for Condition { - fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult { - Ok(depythonize(ob)?) +impl<'source> FromPyObject<'_, 'source> for Condition { + type Error = PyErr; + + fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result { + Ok(depythonize(&ob)?) } }