Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump and migrate pyo3 to 0.21 #121

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-asyncio"
description = "PyO3 utilities for Python's Asyncio library"
version = "0.20.0"
version = "0.21.0"
authors = ["Andrew J Westlake <[email protected]>"]
readme = "README.md"
keywords = ["pyo3", "python", "ffi", "async", "asyncio"]
Expand Down Expand Up @@ -116,11 +116,11 @@ futures = "0.3"
inventory = { version = "0.3", optional = true }
once_cell = "1.14"
pin-project-lite = "0.2"
pyo3 = "0.20"
pyo3-asyncio-macros = { path = "pyo3-asyncio-macros", version = "=0.20.0", optional = true }
pyo3 = "0.21"
pyo3-asyncio-macros = { path = "pyo3-asyncio-macros", version = "=0.21.0", optional = true }

[dev-dependencies]
pyo3 = { version = "0.20", features = ["macros"] }
pyo3 = { version = "0.21", features = ["macros"] }

[dependencies.async-std]
version = "1.12"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use pyo3::prelude::*;
#[pyo3_asyncio::async_std::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import("asyncio")?;
let asyncio = py.import_bound("asyncio")?;
// convert asyncio.sleep into a Rust Future
pyo3_asyncio::async_std::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
})?;
Expand Down Expand Up @@ -95,7 +95,7 @@ use pyo3::prelude::*;
#[pyo3_asyncio::tokio::main]
async fn main() -> PyResult<()> {
let fut = Python::with_gil(|py| {
let asyncio = py.import("asyncio")?;
let asyncio = py.import_bound("asyncio")?;
// convert asyncio.sleep into a Rust Future
pyo3_asyncio::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
})?;
Expand Down Expand Up @@ -149,7 +149,7 @@ Export an async function that makes use of `async-std`:
use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
fn rust_sleep(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::async_std::future_into_py(py, async {
async_std::task::sleep(std::time::Duration::from_secs(1)).await;
Ok(())
Expand All @@ -173,7 +173,7 @@ If you want to use `tokio` instead, here's what your module should look like:
use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
fn rust_sleep(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::tokio::future_into_py(py, async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
Ok(())
Expand Down Expand Up @@ -237,7 +237,7 @@ use pyo3::prelude::*;
async fn main() -> PyResult<()> {
let future = Python::with_gil(|py| -> PyResult<_> {
// import the module containing the py_sleep function
let example = py.import("example")?;
let example = py.import_bound("example")?;

// calling the py_sleep method like a normal function
// returns a coroutine
Expand Down Expand Up @@ -289,7 +289,7 @@ async fn rust_sleep() {
}

#[pyfunction]
fn call_rust_sleep(py: Python) -> PyResult<&PyAny> {
fn call_rust_sleep(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::async_std::future_into_py(py, async move {
rust_sleep().await;
Ok(())
Expand Down Expand Up @@ -356,7 +356,7 @@ async fn main() -> PyResult<()> {
// PyO3 is initialized - Ready to go

let fut = Python::with_gil(|py| -> PyResult<_> {
let asyncio = py.import("asyncio")?;
let asyncio = py.import_bound("asyncio")?;

// convert asyncio.sleep into a Rust Future
pyo3_asyncio::async_std::into_future(
Expand Down Expand Up @@ -443,7 +443,7 @@ tokio = "1.9"
use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
fn rust_sleep(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::tokio::future_into_py(py, async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
Ok(())
Expand Down Expand Up @@ -504,7 +504,7 @@ fn main() -> PyResult<()> {
pyo3::prepare_freethreaded_python();

Python::with_gil(|py| {
let uvloop = py.import("uvloop")?;
let uvloop = py.import_bound("uvloop")?;
uvloop.call_method0("install")?;

// store a reference for the assertion
Expand All @@ -514,7 +514,7 @@ fn main() -> PyResult<()> {
// verify that we are on a uvloop.Loop
Python::with_gil(|py| -> PyResult<()> {
assert!(uvloop
.as_ref(py)
.bind(py)
.getattr("Loop")?
.downcast::<PyType>()
.unwrap()
Expand Down Expand Up @@ -601,7 +601,7 @@ To make things a bit easier, I decided to keep most of the old API alongside the
pyo3::prepare_freethreaded_python();

Python::with_gil(|py| {
let asyncio = py.import("asyncio")?;
let asyncio = py.import_bound("asyncio")?;

let event_loop = asyncio.call_method0("new_event_loop")?;
asyncio.call_method1("set_event_loop", (event_loop,))?;
Expand All @@ -614,11 +614,11 @@ To make things a bit easier, I decided to keep most of the old API alongside the
// Stop the event loop manually
Python::with_gil(|py| {
event_loop_hdl
.as_ref(py)
.bind(py)
.call_method1(
"call_soon_threadsafe",
(event_loop_hdl
.as_ref(py)
.bind(py)
.getattr("stop")
.unwrap(),),
)
Expand Down
2 changes: 1 addition & 1 deletion pyo3-asyncio-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-asyncio-macros"
description = "Proc Macro Attributes for PyO3 Asyncio"
version = "0.20.0"
version = "0.21.0"
authors = ["Andrew J Westlake <[email protected]>"]
readme = "../README.md"
keywords = ["pyo3", "python", "ffi", "async", "asyncio"]
Expand Down
6 changes: 3 additions & 3 deletions pytests/test_async_std_asyncio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use pyo3_asyncio::TaskLocals;
use futures::{StreamExt, TryStreamExt};

#[pyfunction]
fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
fn sleep<'p>(py: Python<'p>, secs: Bound<PyAny>) -> PyResult<Bound<PyAny>> {
let secs = secs.extract()?;

pyo3_asyncio::async_std::future_into_py(py, async move {
Expand Down Expand Up @@ -258,7 +258,7 @@ fn test_local_cancel(event_loop: PyObject) -> PyResult<()> {
fn test_mod(_py: Python, m: &PyModule) -> PyResult<()> {
#![allow(deprecated)]
#[pyfunction(name = "sleep")]
fn sleep_(py: Python) -> PyResult<&PyAny> {
fn sleep_(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::async_std::future_into_py(py, async move {
async_std::task::sleep(Duration::from_millis(500)).await;
Ok(())
Expand Down Expand Up @@ -305,7 +305,7 @@ fn test_multiple_asyncio_run() -> PyResult<()> {
fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
#![allow(deprecated)]
#[pyfunction]
pub(crate) fn async_callback(py: Python, callback: PyObject) -> PyResult<&PyAny> {
pub(crate) fn async_callback(py: Python, callback: PyObject) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::async_std::future_into_py(py, async move {
Python::with_gil(|py| {
pyo3_asyncio::async_std::into_future(callback.as_ref(py).call0()?)
Expand Down
2 changes: 1 addition & 1 deletion pytests/test_race_condition_regression.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
fn sleep<'p>(py: Python<'p>, secs: Bound<PyAny>) -> PyResult<Bound<PyAny>> {
let secs = secs.extract()?;

pyo3_asyncio::async_std::future_into_py(py, async move {
Expand Down
6 changes: 3 additions & 3 deletions pytests/tokio_asyncio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use futures::{StreamExt, TryStreamExt};
use crate::common;

#[pyfunction]
fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
fn sleep<'p>(py: Python<'p>, secs: Bound<PyAny>) -> PyResult<Bound<PyAny>> {
let secs = secs.extract()?;

pyo3_asyncio::tokio::future_into_py(py, async move {
Expand Down Expand Up @@ -233,7 +233,7 @@ fn test_local_cancel(event_loop: PyObject) -> PyResult<()> {
fn test_mod(_py: Python, m: &PyModule) -> PyResult<()> {
#![allow(deprecated)]
#[pyfunction(name = "sleep")]
fn sleep_(py: Python) -> PyResult<&PyAny> {
fn sleep_(py: Python) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::tokio::future_into_py(py, async move {
tokio::time::sleep(Duration::from_millis(500)).await;
Ok(())
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_multiple_asyncio_run() -> PyResult<()> {
fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
#![allow(deprecated)]
#[pyfunction]
fn async_callback(py: Python, callback: PyObject) -> PyResult<&PyAny> {
fn async_callback(py: Python, callback: PyObject) -> PyResult<Bound<PyAny>> {
pyo3_asyncio::tokio::future_into_py(py, async move {
Python::with_gil(|py| pyo3_asyncio::tokio::into_future(callback.as_ref(py).call0()?))?
.await?;
Expand Down
Loading