1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to specify return type in an async Python function?

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    In TypeScript, you would do something like

    async function getString(word: string): Promise<string> {
    return word;
    }


    How can I do the same in Python? I tried the following:

    async def get_string(word: str) -> Coroutine[str]:
    return word


    And got this traceback:

    TypeError: Too few parameters for typing.Coroutine; actual 1, expected 3


    So Coroutine expects 3 types. But why? And what should they be in this case?

    This is also specified in the docs, but I still don't understand

    Continue reading...

Compartilhe esta Página