![](https://secure.gravatar.com/avatar/d67ab5d94c2fed8ab6b727b62dc1b213.jpg?s=120&d=mm&r=g)
On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas <python-ideas@python.org> wrote:
After getting used to writing async functions, I’ve been wanting use a similar syntax to declare generator functions. Something along the lines of
`iter def my_iterator() -> T`
and/or
`gen def my_generator() -> (T, U, V)`
Obviously, for backwards compatibility, this would need to be optional or have an opt-in mechanism. Would a feature like this be at all within the realm of possibility? I’d be happy to write up a much longer discussion if so.
(I found a short discussion of such a feature in the archives about 8 years ago[1]. But, since it predates both `async def` and the current type checker regime, I thought it might be worth discussing. Apologies if I missed any more recent discussions.)
What's the advantage? You can just use normal function syntax to define them, and it works correctly. Do you need the ability to declare that it's a generator even without any yields in it? ChrisA