Skip to content

Commit d02796f

Browse files
authored
Bump pyo3 from 0.26.0 to 0.27.2 and pythonize from 0.26.0 to 0.27.0 (#19412)
Hello, I'm writing on behalf of the Citadel product developed by ERCOM. This PR bumps `pyo3` from 0.26.0 to 0.27.2 and `pythonize` from 0.26.0 to 0.27.0. For the code migration I followed the guide found here: [link](https://pyo3.rs/v0.27.0/migration.html).
1 parent ede0f4f commit d02796f

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

changelog.d/19412.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ http = "1.1.0"
3030
lazy_static = "1.4.0"
3131
log = "0.4.17"
3232
mime = "0.3.17"
33-
pyo3 = { version = "0.26.0", features = [
33+
pyo3 = { version = "0.27.2", features = [
3434
"macros",
3535
"anyhow",
3636
"abi3",
3737
"abi3-py310",
3838
] }
3939
pyo3-log = "0.13.1"
40-
pythonize = "0.26.0"
40+
pythonize = "0.27.0"
4141
regex = "1.6.0"
4242
sha2 = "0.10.8"
4343
serde = { version = "1.0.144", features = ["derive"] }

rust/src/http.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn read_io_body(body: &Bound<'_, PyAny>, chunk_size: usize) -> PyResult<Bytes> {
3232
let mut buf = BytesMut::new();
3333
loop {
3434
let bound = &body.call_method1("read", (chunk_size,))?;
35-
let bytes: &Bound<'_, PyBytes> = bound.downcast()?;
35+
let bytes: &Bound<'_, PyBytes> = bound.cast()?;
3636
if bytes.as_bytes().is_empty() {
3737
return Ok(buf.into());
3838
}
@@ -58,12 +58,12 @@ pub fn http_request_from_twisted(request: &Bound<'_, PyAny>) -> PyResult<Request
5858
let mut req = Request::new(body);
5959

6060
let bound = &request.getattr("uri")?;
61-
let uri: &Bound<'_, PyBytes> = bound.downcast()?;
61+
let uri: &Bound<'_, PyBytes> = bound.cast()?;
6262
*req.uri_mut() =
6363
Uri::try_from(uri.as_bytes()).map_err(|_| PyValueError::new_err("invalid uri"))?;
6464

6565
let bound = &request.getattr("method")?;
66-
let method: &Bound<'_, PyBytes> = bound.downcast()?;
66+
let method: &Bound<'_, PyBytes> = bound.cast()?;
6767
*req.method_mut() = Method::from_bytes(method.as_bytes())
6868
.map_err(|_| PyValueError::new_err("invalid method"))?;
6969

@@ -74,17 +74,17 @@ pub fn http_request_from_twisted(request: &Bound<'_, PyAny>) -> PyResult<Request
7474

7575
for header in headers_iter {
7676
let header = header?;
77-
let header: &Bound<'_, PyTuple> = header.downcast()?;
77+
let header: &Bound<'_, PyTuple> = header.cast()?;
7878
let bound = &header.get_item(0)?;
79-
let name: &Bound<'_, PyBytes> = bound.downcast()?;
79+
let name: &Bound<'_, PyBytes> = bound.cast()?;
8080
let name = HeaderName::from_bytes(name.as_bytes())
8181
.map_err(|_| PyValueError::new_err("invalid header name"))?;
8282

8383
let bound = &header.get_item(1)?;
84-
let values: &Bound<'_, PySequence> = bound.downcast()?;
84+
let values: &Bound<'_, PySequence> = bound.cast()?;
8585
for index in 0..values.len()? {
8686
let bound = &values.get_item(index)?;
87-
let value: &Bound<'_, PyBytes> = bound.downcast()?;
87+
let value: &Bound<'_, PyBytes> = bound.cast()?;
8888
let value = HeaderValue::from_bytes(value.as_bytes())
8989
.map_err(|_| PyValueError::new_err("invalid header value"))?;
9090
req.headers_mut().append(name.clone(), value);

rust/src/http_client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,8 @@ fn make_deferred_yieldable<'py>(
316316
func
317317
});
318318

319-
make_deferred_yieldable.call1(py, (deferred,))?.extract(py)
319+
make_deferred_yieldable
320+
.call1(py, (deferred,))?
321+
.extract(py)
322+
.map_err(Into::into)
320323
}

rust/src/push/mod.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,16 @@ pub enum SimpleJsonValue {
273273
Null,
274274
}
275275

276-
impl<'source> FromPyObject<'source> for SimpleJsonValue {
277-
fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult<Self> {
278-
if let Ok(s) = ob.downcast::<PyString>() {
276+
impl<'source> FromPyObject<'_, 'source> for SimpleJsonValue {
277+
type Error = PyErr;
278+
279+
fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result<Self, Self::Error> {
280+
if let Ok(s) = ob.cast::<PyString>() {
279281
Ok(SimpleJsonValue::Str(Cow::Owned(s.to_string())))
280282
// A bool *is* an int, ensure we try bool first.
281-
} else if let Ok(b) = ob.downcast::<PyBool>() {
283+
} else if let Ok(b) = ob.cast::<PyBool>() {
282284
Ok(SimpleJsonValue::Bool(b.extract()?))
283-
} else if let Ok(i) = ob.downcast::<PyInt>() {
285+
} else if let Ok(i) = ob.cast::<PyInt>() {
284286
Ok(SimpleJsonValue::Int(i.extract()?))
285287
} else if ob.is_none() {
286288
Ok(SimpleJsonValue::Null)
@@ -301,20 +303,22 @@ pub enum JsonValue {
301303
Value(SimpleJsonValue),
302304
}
303305

304-
impl<'source> FromPyObject<'source> for JsonValue {
305-
fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult<Self> {
306-
if let Ok(l) = ob.downcast::<PyList>() {
306+
impl<'source> FromPyObject<'_, 'source> for JsonValue {
307+
type Error = PyErr;
308+
309+
fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result<Self, Self::Error> {
310+
if let Ok(l) = ob.cast::<PyList>() {
307311
match l
308312
.iter()
309-
.map(|it| SimpleJsonValue::extract_bound(&it))
313+
.map(|it| SimpleJsonValue::extract(it.as_borrowed()))
310314
.collect()
311315
{
312316
Ok(a) => Ok(JsonValue::Array(a)),
313317
Err(e) => Err(PyTypeError::new_err(format!(
314318
"Can't convert to JsonValue::Array: {e}"
315319
))),
316320
}
317-
} else if let Ok(v) = SimpleJsonValue::extract_bound(ob) {
321+
} else if let Ok(v) = SimpleJsonValue::extract(ob) {
318322
Ok(JsonValue::Value(v))
319323
} else {
320324
Err(PyTypeError::new_err(format!(
@@ -385,9 +389,11 @@ impl<'source> IntoPyObject<'source> for Condition {
385389
}
386390
}
387391

388-
impl<'source> FromPyObject<'source> for Condition {
389-
fn extract_bound(ob: &Bound<'source, PyAny>) -> PyResult<Self> {
390-
Ok(depythonize(ob)?)
392+
impl<'source> FromPyObject<'_, 'source> for Condition {
393+
type Error = PyErr;
394+
395+
fn extract(ob: Borrowed<'_, 'source, PyAny>) -> Result<Self, Self::Error> {
396+
Ok(depythonize(&ob)?)
391397
}
392398
}
393399

0 commit comments

Comments
 (0)