Skip to content

Commit 6e80625

Browse files
author
Andrew J Westlake
committed
Removed 0.14 deprecations
1 parent 4ee9e9a commit 6e80625

File tree

7 files changed

+7
-499
lines changed

7 files changed

+7
-499
lines changed

pytests/common/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ pub(super) async fn test_into_future(event_loop: PyObject) -> PyResult<()> {
2929
Ok(())
3030
}
3131

32-
#[allow(deprecated)]
33-
pub(super) async fn test_into_future_0_13() -> PyResult<()> {
34-
let fut = Python::with_gil(|py| {
35-
let test_mod =
36-
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?;
37-
38-
pyo3_asyncio::into_future(test_mod.call_method1("py_sleep", (1.into_py(py),))?)
39-
})?;
40-
41-
fut.await?;
42-
43-
Ok(())
44-
}
45-
4632
pub(super) fn test_blocking_sleep() -> PyResult<()> {
4733
thread::sleep(Duration::from_secs(1));
4834
Ok(())

pytests/test_async_std_asyncio.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ use pyo3::{
1515
};
1616
use pyo3_asyncio::TaskLocals;
1717

18-
#[pyfunction]
19-
#[allow(deprecated)]
20-
fn sleep_into_coroutine(py: Python, secs: &PyAny) -> PyResult<PyObject> {
21-
let secs = secs.extract()?;
22-
23-
pyo3_asyncio::async_std::into_coroutine(py, async move {
24-
task::sleep(Duration::from_secs(secs)).await;
25-
Python::with_gil(|py| Ok(py.None()))
26-
})
27-
}
28-
2918
#[pyfunction]
3019
fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
3120
let secs = secs.extract()?;
@@ -36,38 +25,6 @@ fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
3625
})
3726
}
3827

39-
#[pyo3_asyncio::async_std::test]
40-
fn test_into_coroutine() -> PyResult<()> {
41-
#[allow(deprecated)]
42-
Python::with_gil(|py| {
43-
let sleeper_mod = PyModule::new(py, "rust_sleeper")?;
44-
45-
sleeper_mod.add_wrapped(wrap_pyfunction!(sleep_into_coroutine))?;
46-
47-
let test_mod = PyModule::from_code(
48-
py,
49-
common::TEST_MOD,
50-
"test_into_coroutine_mod.py",
51-
"test_into_coroutine_mod",
52-
)?;
53-
54-
let fut = pyo3_asyncio::into_future(test_mod.call_method1(
55-
"sleep_for_1s",
56-
(sleeper_mod.getattr("sleep_into_coroutine")?,),
57-
)?)?;
58-
59-
pyo3_asyncio::async_std::run_until_complete(
60-
pyo3_asyncio::get_event_loop(py),
61-
async move {
62-
fut.await?;
63-
Ok(())
64-
},
65-
)?;
66-
67-
Ok(())
68-
})
69-
}
70-
7128
#[pyo3_asyncio::async_std::test]
7229
async fn test_future_into_py() -> PyResult<()> {
7330
let fut = Python::with_gil(|py| {
@@ -122,11 +79,6 @@ async fn test_into_future() -> PyResult<()> {
12279
.await
12380
}
12481

125-
#[pyo3_asyncio::async_std::test]
126-
async fn test_into_future_0_13() -> PyResult<()> {
127-
common::test_into_future_0_13().await
128-
}
129-
13082
#[pyo3_asyncio::async_std::test]
13183
async fn test_other_awaitables() -> PyResult<()> {
13284
common::test_other_awaitables(Python::with_gil(|py| {

pytests/tokio_asyncio/mod.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ use pyo3_asyncio::TaskLocals;
1414

1515
use crate::common;
1616

17-
#[pyfunction]
18-
#[allow(deprecated)]
19-
fn sleep_into_coroutine(py: Python, secs: &PyAny) -> PyResult<PyObject> {
20-
let secs = secs.extract()?;
21-
22-
pyo3_asyncio::tokio::into_coroutine(py, async move {
23-
tokio::time::sleep(Duration::from_secs(secs)).await;
24-
Python::with_gil(|py| Ok(py.None()))
25-
})
26-
}
27-
2817
#[pyfunction]
2918
fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
3019
let secs = secs.extract()?;
@@ -35,35 +24,6 @@ fn sleep<'p>(py: Python<'p>, secs: &'p PyAny) -> PyResult<&'p PyAny> {
3524
})
3625
}
3726

38-
#[pyo3_asyncio::tokio::test]
39-
fn test_into_coroutine() -> PyResult<()> {
40-
#[allow(deprecated)]
41-
Python::with_gil(|py| {
42-
let sleeper_mod = PyModule::new(py, "rust_sleeper")?;
43-
44-
sleeper_mod.add_wrapped(wrap_pyfunction!(sleep_into_coroutine))?;
45-
46-
let test_mod = PyModule::from_code(
47-
py,
48-
common::TEST_MOD,
49-
"test_into_coroutine_mod.py",
50-
"test_into_coroutine_mod",
51-
)?;
52-
53-
let fut = pyo3_asyncio::into_future(test_mod.call_method1(
54-
"sleep_for_1s",
55-
(sleeper_mod.getattr("sleep_into_coroutine")?,),
56-
)?)?;
57-
58-
pyo3_asyncio::tokio::run_until_complete(pyo3_asyncio::get_event_loop(py), async move {
59-
fut.await?;
60-
Ok(())
61-
})?;
62-
63-
Ok(())
64-
})
65-
}
66-
6727
#[pyo3_asyncio::tokio::test]
6828
async fn test_future_into_py() -> PyResult<()> {
6929
let fut = Python::with_gil(|py| {
@@ -116,11 +76,6 @@ async fn test_into_future() -> PyResult<()> {
11676
.await
11777
}
11878

119-
#[pyo3_asyncio::tokio::test]
120-
async fn test_into_future_0_13() -> PyResult<()> {
121-
common::test_into_future_0_13().await
122-
}
123-
12479
#[pyo3_asyncio::tokio::test]
12580
async fn test_other_awaitables() -> PyResult<()> {
12681
common::test_other_awaitables(Python::with_gil(|py| {

src/async_std.rs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,14 @@ pub fn get_current_locals(py: Python) -> PyResult<TaskLocals> {
156156
/// #
157157
/// # pyo3::prepare_freethreaded_python();
158158
/// #
159-
/// # Python::with_gil(|py| {
160-
/// # pyo3_asyncio::with_runtime(py, || {
159+
/// # Python::with_gil(|py| -> PyResult<()> {
161160
/// # let event_loop = py.import("asyncio")?.call_method0("new_event_loop")?;
162161
/// pyo3_asyncio::async_std::run_until_complete(event_loop, async move {
163162
/// async_std::task::sleep(Duration::from_secs(1)).await;
164163
/// Ok(())
165164
/// })?;
166165
/// # Ok(())
167-
/// # })
168-
/// # .map_err(|e| {
169-
/// # e.print_and_set_sys_last_vars(py);
170-
/// # })
171-
/// # .unwrap();
172-
/// # });
166+
/// # }).unwrap();
173167
/// ```
174168
pub fn run_until_complete<F>(event_loop: &PyAny, fut: F) -> PyResult<()>
175169
where
@@ -214,42 +208,6 @@ where
214208
generic::run::<AsyncStdRuntime, F>(py, fut)
215209
}
216210

217-
/// Convert a Rust Future into a Python awaitable
218-
///
219-
/// # Arguments
220-
/// * `py` - The current PyO3 GIL guard
221-
/// * `fut` - The Rust future to be converted
222-
///
223-
/// # Examples
224-
///
225-
/// ```
226-
/// use std::time::Duration;
227-
///
228-
/// use pyo3::prelude::*;
229-
///
230-
/// /// Awaitable sleep function
231-
/// #[pyfunction]
232-
/// fn sleep_for(py: Python, secs: &PyAny) -> PyResult<PyObject> {
233-
/// let secs = secs.extract()?;
234-
///
235-
/// pyo3_asyncio::async_std::into_coroutine(py, async move {
236-
/// async_std::task::sleep(Duration::from_secs(secs)).await;
237-
/// Python::with_gil(|py| Ok(py.None()))
238-
/// })
239-
/// }
240-
/// ```
241-
#[deprecated(
242-
since = "0.14.0",
243-
note = "Use the pyo3_asyncio::async_std::future_into_py instead\n (see the [migration guide](https://github.com/awestlake87/pyo3-asyncio/#migrating-from-013-to-014) for more details)"
244-
)]
245-
#[allow(deprecated)]
246-
pub fn into_coroutine<F>(py: Python, fut: F) -> PyResult<PyObject>
247-
where
248-
F: Future<Output = PyResult<PyObject>> + Send + 'static,
249-
{
250-
generic::into_coroutine::<AsyncStdRuntime, _>(py, fut)
251-
}
252-
253211
/// Convert a Rust Future into a Python awaitable
254212
///
255213
/// # Arguments

src/generic.rs

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pyo3::prelude::*;
1010

1111
#[allow(deprecated)]
1212
use crate::{
13-
asyncio, call_soon_threadsafe, close, create_future, dump_err, err::RustPanic, get_event_loop,
13+
asyncio, call_soon_threadsafe, close, create_future, dump_err, err::RustPanic,
1414
get_running_loop, into_future_with_locals, TaskLocals,
1515
};
1616

@@ -156,21 +156,15 @@ where
156156
/// #
157157
/// # use pyo3::prelude::*;
158158
/// #
159-
/// # Python::with_gil(|py| {
160-
/// # pyo3_asyncio::with_runtime(py, || {
159+
/// # Python::with_gil(|py| -> PyResult<()> {
161160
/// # let event_loop = py.import("asyncio")?.call_method0("new_event_loop")?;
162161
/// # #[cfg(feature = "tokio-runtime")]
163162
/// pyo3_asyncio::generic::run_until_complete::<MyCustomRuntime, _>(event_loop, async move {
164163
/// tokio::time::sleep(Duration::from_secs(1)).await;
165164
/// Ok(())
166165
/// })?;
167166
/// # Ok(())
168-
/// # })
169-
/// # .map_err(|e| {
170-
/// # e.print_and_set_sys_last_vars(py);
171-
/// # })
172-
/// # .unwrap();
173-
/// # });
167+
/// # }).unwrap();
174168
/// ```
175169
pub fn run_until_complete<R, F>(event_loop: &PyAny, fut: F) -> PyResult<()>
176170
where
@@ -1032,99 +1026,6 @@ where
10321026
future_into_py::<R, F>(py, fut)
10331027
}
10341028

1035-
/// Convert a Rust Future into a Python awaitable with a generic runtime
1036-
///
1037-
/// # Arguments
1038-
/// * `py` - The current PyO3 GIL guard
1039-
/// * `fut` - The Rust future to be converted
1040-
///
1041-
/// # Examples
1042-
///
1043-
/// ```no_run
1044-
/// # use std::{task::{Context, Poll}, pin::Pin, future::Future};
1045-
/// #
1046-
/// # use pyo3_asyncio::{
1047-
/// # TaskLocals,
1048-
/// # generic::{JoinError, SpawnLocalExt, ContextExt, LocalContextExt, Runtime}
1049-
/// # };
1050-
/// #
1051-
/// # struct MyCustomJoinError;
1052-
/// #
1053-
/// # impl JoinError for MyCustomJoinError {
1054-
/// # fn is_panic(&self) -> bool {
1055-
/// # unreachable!()
1056-
/// # }
1057-
/// # }
1058-
/// #
1059-
/// # struct MyCustomJoinHandle;
1060-
/// #
1061-
/// # impl Future for MyCustomJoinHandle {
1062-
/// # type Output = Result<(), MyCustomJoinError>;
1063-
/// #
1064-
/// # fn poll(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> {
1065-
/// # unreachable!()
1066-
/// # }
1067-
/// # }
1068-
/// #
1069-
/// # struct MyCustomRuntime;
1070-
/// #
1071-
/// # impl MyCustomRuntime {
1072-
/// # async fn sleep(_: Duration) {
1073-
/// # unreachable!()
1074-
/// # }
1075-
/// # }
1076-
/// #
1077-
/// # impl Runtime for MyCustomRuntime {
1078-
/// # type JoinError = MyCustomJoinError;
1079-
/// # type JoinHandle = MyCustomJoinHandle;
1080-
/// #
1081-
/// # fn spawn<F>(fut: F) -> Self::JoinHandle
1082-
/// # where
1083-
/// # F: Future<Output = ()> + Send + 'static
1084-
/// # {
1085-
/// # unreachable!()
1086-
/// # }
1087-
/// # }
1088-
/// #
1089-
/// # impl ContextExt for MyCustomRuntime {
1090-
/// # fn scope<F, R>(locals: TaskLocals, fut: F) -> Pin<Box<dyn Future<Output = R> + Send>>
1091-
/// # where
1092-
/// # F: Future<Output = R> + Send + 'static
1093-
/// # {
1094-
/// # unreachable!()
1095-
/// # }
1096-
/// # fn get_task_locals() -> Option<TaskLocals> {
1097-
/// # unreachable!()
1098-
/// # }
1099-
/// # }
1100-
/// #
1101-
/// use std::time::Duration;
1102-
///
1103-
/// use pyo3::prelude::*;
1104-
///
1105-
/// /// Awaitable sleep function
1106-
/// #[pyfunction]
1107-
/// fn sleep_for(py: Python, secs: &PyAny) -> PyResult<PyObject> {
1108-
/// let secs = secs.extract()?;
1109-
/// pyo3_asyncio::generic::into_coroutine::<MyCustomRuntime, _>(py, async move {
1110-
/// MyCustomRuntime::sleep(Duration::from_secs(secs)).await;
1111-
/// Python::with_gil(|py| Ok(py.None()))
1112-
/// })
1113-
/// }
1114-
/// ```
1115-
#[deprecated(
1116-
since = "0.14.0",
1117-
note = "Use the pyo3_asyncio::generic::future_into_py instead\n (see the [migration guide](https://github.com/awestlake87/pyo3-asyncio/#migrating-from-013-to-014) for more details)"
1118-
)]
1119-
#[allow(deprecated)]
1120-
pub fn into_coroutine<R, F>(py: Python, fut: F) -> PyResult<PyObject>
1121-
where
1122-
R: Runtime + ContextExt,
1123-
F: Future<Output = PyResult<PyObject>> + Send + 'static,
1124-
{
1125-
Ok(future_into_py_with_loop::<R, F>(get_event_loop(py), fut)?.into())
1126-
}
1127-
11281029
/// Convert a `!Send` Rust Future into a Python awaitable with a generic runtime
11291030
///
11301031
/// # Arguments

0 commit comments

Comments
 (0)