Skip to content

Commit 0837d91

Browse files
authored
pyo3 downcasts changed to casts (#65)
* pyo3 downcasts changed to casts * update changelog
1 parent 94b1c25 commit 0837d91

File tree

7 files changed

+12
-32
lines changed

7 files changed

+12
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ To see unreleased changes, please see the CHANGELOG on the main branch.
1515
Trait `Runtime` now requires `spawn_blocking` function,
1616
`future_into_py` functions now require future return type to be `Send`.
1717
[#60](https://github.com/PyO3/pyo3-async-runtimes/pull/60)
18+
- Change pyo3 `downcast` calls to `cast` calls [#65](https://github.com/PyO3/pyo3-async-runtimes/pull/65)
1819

1920
## [0.26.0] - 2025-09-02
2021

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn main() -> PyResult<()> {
515515
assert!(uvloop
516516
.bind(py)
517517
.getattr("Loop")?
518-
.downcast::<PyType>()
518+
.cast::<PyType>()
519519
.unwrap()
520520
.is_instance(&pyo3_async_runtimes::async_std::get_current_loop(py)?)?);
521521
Ok(())

pytests/test_async_std_asyncio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async fn test_cancel() -> PyResult<()> {
158158
assert!(e.value(py).is_instance(
159159
py.import("asyncio")?
160160
.getattr("CancelledError")?
161-
.downcast::<PyType>()
161+
.cast::<PyType>()
162162
.unwrap()
163163
)?);
164164
Ok(())
@@ -240,7 +240,7 @@ fn test_local_cancel(event_loop: Py<PyAny>) -> PyResult<()> {
240240
assert!(e.value(py).is_instance(
241241
py.import("asyncio")?
242242
.getattr("CancelledError")?
243-
.downcast::<PyType>()
243+
.cast::<PyType>()
244244
.unwrap()
245245
)?);
246246
Ok(())

pytests/test_async_std_uvloop.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ fn main() -> pyo3::PyResult<()> {
2626
pyo3_async_runtimes::async_std::run(py, async move {
2727
// verify that we are on a uvloop.Loop
2828
Python::attach(|py| -> PyResult<()> {
29-
assert!(
30-
pyo3_async_runtimes::async_std::get_current_loop(py)?.is_instance(
31-
uvloop
32-
.bind(py)
33-
.getattr("Loop")?
34-
.downcast::<PyType>()
35-
.unwrap()
36-
)?
37-
);
29+
assert!(pyo3_async_runtimes::async_std::get_current_loop(py)?
30+
.is_instance(uvloop.bind(py).getattr("Loop")?.cast::<PyType>().unwrap())?);
3831
Ok(())
3932
})?;
4033

pytests/test_tokio_current_thread_uvloop.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,8 @@ fn main() -> pyo3::PyResult<()> {
3535
pyo3_async_runtimes::tokio::run(py, async move {
3636
// verify that we are on a uvloop.Loop
3737
Python::attach(|py| -> PyResult<()> {
38-
assert!(
39-
pyo3_async_runtimes::tokio::get_current_loop(py)?.is_instance(
40-
uvloop
41-
.bind(py)
42-
.getattr("Loop")?
43-
.downcast::<PyType>()
44-
.unwrap()
45-
)?
46-
);
38+
assert!(pyo3_async_runtimes::tokio::get_current_loop(py)?
39+
.is_instance(uvloop.bind(py).getattr("Loop")?.cast::<PyType>().unwrap())?);
4740
Ok(())
4841
})?;
4942

pytests/test_tokio_multi_thread_uvloop.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,8 @@ fn main() -> pyo3::PyResult<()> {
2727
pyo3_async_runtimes::tokio::run(py, async move {
2828
// verify that we are on a uvloop.Loop
2929
Python::attach(|py| -> PyResult<()> {
30-
assert!(
31-
pyo3_async_runtimes::tokio::get_current_loop(py)?.is_instance(
32-
uvloop
33-
.bind(py)
34-
.getattr("Loop")?
35-
.downcast::<PyType>()
36-
.unwrap()
37-
)?
38-
);
30+
assert!(pyo3_async_runtimes::tokio::get_current_loop(py)?
31+
.is_instance(uvloop.bind(py).getattr("Loop")?.cast::<PyType>().unwrap())?);
3932
Ok(())
4033
})?;
4134

pytests/tokio_asyncio/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async fn test_cancel() -> PyResult<()> {
164164
assert!(e.value(py).is_instance(
165165
py.import("asyncio")?
166166
.getattr("CancelledError")?
167-
.downcast::<PyType>()
167+
.cast::<PyType>()
168168
.unwrap()
169169
)?);
170170
Ok(())
@@ -216,7 +216,7 @@ fn test_local_cancel(event_loop: Py<PyAny>) -> PyResult<()> {
216216
assert!(e.value(py).is_instance(
217217
py.import("asyncio")?
218218
.getattr("CancelledError")?
219-
.downcast::<PyType>()
219+
.cast::<PyType>()
220220
.unwrap()
221221
)?);
222222
Ok(())

0 commit comments

Comments
 (0)