# Ambivalent async generator function signature

**URL:** <https://discuss.python.org/t/ambivalent-async-generator-function-signature/71439>\
**Category:** Typing\
**Created:** [November 17, 2024, 9:05am UTC](https://discuss.python.org/t/ambivalent-async-generator-function-signature/71439 "2024-11-17T09:05:44Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mikeshardmind](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mikeshardmind/32/14381_2.png) [@mikeshardmind](https://discuss.python.org/u/mikeshardmind)\
**Post date:** [November 18, 2024, 4:26am UTC](https://discuss.python.org/t/ambivalent-async-generator-function-signature/71439/3 "2024-11-18T04:26:29Z")

</div>

I said it in the thread you linked, but the problem with reading the function body isn’t limited to backwards compatibility or stubs. It also means someone can erroneously change the function body without touching the type signature and have the type of the function change.

In line with your second listed option, I think this is the only reasonable option.

> [@Overloads of async generators: inconsistent Coroutine wrapping](https://discuss.python.org/t/overloads-of-async-generators-inconsistent-coroutine-wrapping/56665/11):
>
> I think the best fix for obvious results would be to change the automatic wrapping to only wrap types which cannot naturally be the correct type without wrapping.

for idiomatic async code, nothing changes. for odd cases like a coroutine function that returns an AsyncIterator without being one itself, you’d need:

```py
async def foo() -> Coroutine[Any, Any, AsyncIterator[int]]:
    ...

```

---

_[View the full topic](https://discuss.python.org/t/ambivalent-async-generator-function-signature/71439)._
