Skip to content

Commit eae0830

Browse files
author
Andrew J Westlake
committed
Fixed compile errors after upgrading pyo3 version
1 parent 4ba880d commit eae0830

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

pyo3-asyncio-macros/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,9 @@ pub fn async_std_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
188188
#fn_impl
189189

190190
pyo3_asyncio::inventory::submit! {
191-
#![crate = pyo3_asyncio] {
192-
pyo3_asyncio::testing::Test {
193-
name: format!("{}::{}", std::module_path!(), stringify!(#name)),
194-
test_fn: &#name
195-
}
191+
pyo3_asyncio::testing::Test {
192+
name: concat!(std::module_path!(), "::", stringify!(#name)),
193+
test_fn: &#name
196194
}
197195
}
198196
};
@@ -299,11 +297,9 @@ pub fn tokio_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
299297
#fn_impl
300298

301299
pyo3_asyncio::inventory::submit! {
302-
#![crate = pyo3_asyncio] {
303-
pyo3_asyncio::testing::Test {
304-
name: format!("{}::{}", std::module_path!(), stringify!(#name)),
305-
test_fn: &#name
306-
}
300+
pyo3_asyncio::testing::Test {
301+
name: concat!(std::module_path!(), "::", stringify!(#name)),
302+
test_fn: &#name
307303
}
308304
}
309305
};

pytests/test_async_std_asyncio.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async fn test_panic() -> PyResult<()> {
101101
match fut.await {
102102
Ok(_) => panic!("coroutine should panic"),
103103
Err(e) => Python::with_gil(|py| {
104-
if e.is_instance::<pyo3_asyncio::err::RustPanic>(py) {
104+
if e.is_instance_of::<pyo3_asyncio::err::RustPanic>(py) {
105105
Ok(())
106106
} else {
107107
panic!("expected RustPanic err")
@@ -220,14 +220,16 @@ fn test_local_cancel(event_loop: PyObject) -> PyResult<()> {
220220
#[pymodule]
221221
fn test_mod(_py: Python, m: &PyModule) -> PyResult<()> {
222222
#![allow(deprecated)]
223-
#[pyfn(m, "sleep")]
223+
#[pyfunction]
224224
fn sleep(py: Python) -> PyResult<&PyAny> {
225225
pyo3_asyncio::async_std::future_into_py(py, async move {
226226
async_std::task::sleep(Duration::from_millis(500)).await;
227227
Ok(())
228228
})
229229
}
230230

231+
m.add_function(wrap_pyfunction!(sleep, m)?)?;
232+
231233
Ok(())
232234
}
233235

@@ -265,8 +267,8 @@ fn test_multiple_asyncio_run() -> PyResult<()> {
265267
#[pymodule]
266268
fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
267269
#![allow(deprecated)]
268-
#[pyfn(m, "async_callback")]
269-
fn async_callback(py: Python, callback: PyObject) -> PyResult<&PyAny> {
270+
#[pyfunction]
271+
pub(crate) fn async_callback(py: Python, callback: PyObject) -> PyResult<&PyAny> {
270272
pyo3_asyncio::async_std::future_into_py(py, async move {
271273
Python::with_gil(|py| {
272274
pyo3_asyncio::async_std::into_future(callback.as_ref(py).call0()?)
@@ -277,6 +279,8 @@ fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
277279
})
278280
}
279281

282+
m.add_function(wrap_pyfunction!(async_callback, m)?)?;
283+
280284
Ok(())
281285
}
282286

pytests/tokio_asyncio/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async fn test_panic() -> PyResult<()> {
121121
match fut.await {
122122
Ok(_) => panic!("coroutine should panic"),
123123
Err(e) => Python::with_gil(|py| {
124-
if e.is_instance::<pyo3_asyncio::err::RustPanic>(py) {
124+
if e.is_instance_of::<pyo3_asyncio::err::RustPanic>(py) {
125125
Ok(())
126126
} else {
127127
panic!("expected RustPanic err")
@@ -226,14 +226,16 @@ fn test_local_cancel(event_loop: PyObject) -> PyResult<()> {
226226
#[pymodule]
227227
fn test_mod(_py: Python, m: &PyModule) -> PyResult<()> {
228228
#![allow(deprecated)]
229-
#[pyfn(m, "sleep")]
229+
#[pyfunction]
230230
fn sleep(py: Python) -> PyResult<&PyAny> {
231231
pyo3_asyncio::tokio::future_into_py(py, async move {
232232
tokio::time::sleep(Duration::from_millis(500)).await;
233233
Ok(())
234234
})
235235
}
236236

237+
m.add_function(wrap_pyfunction!(sleep, m)?)?;
238+
237239
Ok(())
238240
}
239241

@@ -271,7 +273,7 @@ fn test_multiple_asyncio_run() -> PyResult<()> {
271273
#[pymodule]
272274
fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
273275
#![allow(deprecated)]
274-
#[pyfn(m, "async_callback")]
276+
#[pyfunction]
275277
fn async_callback(py: Python, callback: PyObject) -> PyResult<&PyAny> {
276278
pyo3_asyncio::tokio::future_into_py(py, async move {
277279
Python::with_gil(|py| pyo3_asyncio::tokio::into_future(callback.as_ref(py).call0()?))?
@@ -281,6 +283,8 @@ fn cvars_mod(_py: Python, m: &PyModule) -> PyResult<()> {
281283
})
282284
}
283285

286+
m.add_function(wrap_pyfunction!(async_callback, m)?)?;
287+
284288
Ok(())
285289
}
286290

src/testing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
182182
use std::{future::Future, pin::Pin};
183183

184-
use clap::{App, Arg};
184+
use clap::{Arg, Command};
185185
use futures::stream::{self, StreamExt};
186186
use pyo3::prelude::*;
187187

@@ -232,9 +232,9 @@ impl Default for Args {
232232
/// <TESTNAME> If specified, only run tests containing this string in their names
233233
/// ```
234234
pub fn parse_args() -> Args {
235-
let matches = App::new("PyO3 Asyncio Test Suite")
235+
let matches = Command::new("PyO3 Asyncio Test Suite")
236236
.arg(
237-
Arg::with_name("TESTNAME")
237+
Arg::new("TESTNAME")
238238
.help("If specified, only run tests containing this string in their names"),
239239
)
240240
.get_matches();
@@ -250,7 +250,7 @@ type TestFn = dyn Fn() -> Pin<Box<dyn Future<Output = PyResult<()>> + Send>> + S
250250
#[derive(Clone)]
251251
pub struct Test {
252252
/// The fully qualified name of the test
253-
pub name: String,
253+
pub name: &'static str,
254254
/// The function used to create the task that runs the test.
255255
pub test_fn: &'static TestFn,
256256
}

0 commit comments

Comments
 (0)