Skip to content

Commit dee585a

Browse files
committed
Remove unneeded into_pyobject
1 parent e73690d commit dee585a

File tree

10 files changed

+21
-44
lines changed

10 files changed

+21
-44
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn main() -> PyResult<()> {
6565
let fut = Python::attach(|py| {
6666
let asyncio = py.import("asyncio")?;
6767
// convert asyncio.sleep into a Rust Future
68-
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
68+
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1,))?)
6969
})?;
7070

7171
fut.await?;
@@ -95,7 +95,7 @@ async fn main() -> PyResult<()> {
9595
let fut = Python::attach(|py| {
9696
let asyncio = py.import("asyncio")?;
9797
// convert asyncio.sleep into a Rust Future
98-
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
98+
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1,))?)
9999
})?;
100100

101101
fut.await?;
@@ -359,7 +359,7 @@ async fn main() -> PyResult<()> {
359359
360360
// convert asyncio.sleep into a Rust Future
361361
pyo3_async_runtimes::async_std::into_future(
362-
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?
362+
asyncio.call_method1("sleep", (1,))?
363363
)
364364
})?;
365365

examples/async_std.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ async fn main() -> PyResult<()> {
66
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::async_std::into_future(
10-
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11-
)
9+
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1,))?)
1210
})?;
1311

1412
println!("sleeping for 1s");

examples/tokio.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ async fn main() -> PyResult<()> {
66
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(
10-
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11-
)
9+
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1,))?)
1210
})?;
1311

1412
println!("sleeping for 1s");

examples/tokio_current_thread.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ async fn main() -> PyResult<()> {
66
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(
10-
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11-
)
9+
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1,))?)
1210
})?;
1311

1412
println!("sleeping for 1s");

examples/tokio_multi_thread.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ async fn main() -> PyResult<()> {
66
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(
10-
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11-
)
9+
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1,))?)
1210
})?;
1311

1412
println!("sleeping for 1s");

pytests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(super) async fn test_into_future(event_loop: Py<PyAny>) -> PyResult<()> {
2525

2626
pyo3_async_runtimes::into_future_with_locals(
2727
&TaskLocals::new(event_loop.into_bound(py)),
28-
test_mod.call_method1("py_sleep", (1.into_pyobject(py).unwrap(),))?,
28+
test_mod.call_method1("py_sleep", (1,))?,
2929
)
3030
})?;
3131

src/async_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ where
513513
/// Python::attach(|py| {
514514
/// pyo3_async_runtimes::async_std::into_future(
515515
/// test_mod
516-
/// .call_method1(py, "py_sleep", (seconds.into_pyobject(py).unwrap(),))?
516+
/// .call_method1(py, "py_sleep", (seconds,))?
517517
/// .into_bound(py),
518518
/// )
519519
/// })?

src/generic.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use futures::{channel::mpsc, SinkExt};
3131
use once_cell::sync::OnceCell;
3232
use pin_project_lite::pin_project;
3333
use pyo3::prelude::*;
34-
use pyo3::BoundObject;
34+
use pyo3::{BoundObject, IntoPyObjectExt};
3535
#[cfg(feature = "unstable-streams")]
3636
use std::marker::PhantomData;
3737

@@ -349,10 +349,7 @@ fn set_result(
349349

350350
let (complete, val) = match result {
351351
Ok(val) => (future.getattr("set_result")?, val.into_pyobject(py)?),
352-
Err(err) => (
353-
future.getattr("set_exception")?,
354-
err.into_pyobject(py)?.into_any(),
355-
),
352+
Err(err) => (future.getattr("set_exception")?, err.into_bound_py_any(py)?),
356353
};
357354
call_soon_threadsafe(event_loop, &none, (CheckedCompletor, future, complete, val))?;
358355

@@ -457,7 +454,7 @@ fn set_result(
457454
/// Python::attach(|py| {
458455
/// pyo3_async_runtimes::generic::into_future::<MyCustomRuntime>(
459456
/// test_mod
460-
/// .call_method1(py, "py_sleep", (seconds.into_pyobject(py).unwrap(),))?
457+
/// .call_method1(py, "py_sleep", (seconds,))?
461458
/// .into_bound(py),
462459
/// )
463460
/// })?
@@ -622,10 +619,7 @@ where
622619
let _ = set_result(
623620
&locals2.event_loop(py),
624621
future_tx1.bind(py),
625-
result.and_then(|val| match val.into_pyobject(py) {
626-
Ok(obj) => Ok(obj.into_any().unbind()),
627-
Err(err) => Err(err.into()),
628-
}),
622+
result.and_then(|val| val.into_py_any(py)),
629623
)
630624
.map_err(dump_err(py));
631625
});
@@ -1030,10 +1024,7 @@ where
10301024
let _ = set_result(
10311025
locals2.event_loop.bind(py),
10321026
future_tx1.bind(py),
1033-
result.and_then(|val| match val.into_pyobject(py) {
1034-
Ok(obj) => Ok(obj.into_any().unbind()),
1035-
Err(err) => Err(err.into()),
1036-
}),
1027+
result.and_then(|val| val.into_py_any(py)),
10371028
)
10381029
.map_err(dump_err(py));
10391030
});
@@ -1480,7 +1471,7 @@ where
14801471
{
14811472
fn send(&mut self, py: Python, locals: TaskLocals, item: Py<PyAny>) -> PyResult<Py<PyAny>> {
14821473
match self.tx.try_send(item.clone_ref(py)) {
1483-
Ok(_) => Ok(true.into_pyobject(py)?.into_any().unbind()),
1474+
Ok(_) => true.into_py_any(py),
14841475
Err(e) => {
14851476
if e.is_full() {
14861477
let mut tx = self.tx.clone();
@@ -1492,26 +1483,20 @@ where
14921483
async move {
14931484
if tx.flush().await.is_err() {
14941485
// receiving side disconnected
1495-
return Python::attach(|py| {
1496-
Ok(false.into_pyobject(py)?.into_any().unbind())
1497-
});
1486+
return Python::attach(|py| false.into_py_any(py));
14981487
}
14991488
if tx.send(item).await.is_err() {
15001489
// receiving side disconnected
1501-
return Python::attach(|py| {
1502-
Ok(false.into_pyobject(py)?.into_any().unbind())
1503-
});
1490+
return Python::attach(|py| false.into_py_any(py));
15041491
}
1505-
Python::attach(|py| {
1506-
Ok(true.into_pyobject(py)?.into_any().unbind())
1507-
})
1492+
Python::attach(|py| true.into_py_any(py))
15081493
},
15091494
)?
15101495
.into(),
15111496
)
15121497
})
15131498
} else {
1514-
Ok(false.into_pyobject(py)?.into_any().unbind())
1499+
false.into_py_any(py)
15151500
}
15161501
}
15171502
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn call_soon_threadsafe<'py>(
631631
/// pyo3_async_runtimes::into_future_with_locals(
632632
/// &pyo3_async_runtimes::tokio::get_current_locals(py)?,
633633
/// test_mod
634-
/// .call_method1(py, "py_sleep", (seconds.into_pyobject(py).unwrap(),))?
634+
/// .call_method1(py, "py_sleep", (seconds,))?
635635
/// .into_bound(py),
636636
/// )
637637
/// })?

src/tokio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ where
586586
/// Python::attach(|py| {
587587
/// pyo3_async_runtimes::tokio::into_future(
588588
/// test_mod
589-
/// .call_method1(py, "py_sleep", (seconds.into_pyobject(py).unwrap(),))?
589+
/// .call_method1(py, "py_sleep", (seconds,))?
590590
/// .into_bound(py),
591591
/// )
592592
/// })?

0 commit comments

Comments
 (0)