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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DLMXTYBDTVXBMK2PCXIWGL7WDZT42ON2/ Code of Conduct: http://python.org/psf/codeofconduct/