Skip to content

async functions are not tagged with async #190

@terraputix

Description

@terraputix

PyO3 has experimental support for async/await via the experimental-async feature flag.

An async function like the following

use std::{thread, time::Duration};
use futures::channel::oneshot;
use pyo3::prelude::*;

#[gen_stub_pyfunction]
#[pyfunction]
#[pyo3(signature=(seconds, result=None))]
async fn sleep(seconds: f64, result: Option<PyObject>) -> Option<PyObject> {
    let (tx, rx) = oneshot::channel();
    thread::spawn(move || {
        thread::sleep(Duration::from_secs_f64(seconds));
        tx.send(()).unwrap();
    });
    rx.await.unwrap();
    result
}

will yield a stub function

def sleep(seconds:builtins.float, result:typing.Optional[typing.Any]=None) -> typing.Optional[typing.Any]: ...

instead of

async def sleep(seconds:builtins.float, result:typing.Optional[typing.Any]=None) -> typing.Optional[typing.Any]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions