[Python-ideas] Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
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

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
Thanks for your reply. > What's the advantage? I brought this up thinking about explicitness and readability. Say you want to figure out what this function is doing: def foo() -> t.Iterator[T]: [... 300 lines of code] ``` Is this a generator function? I'd argue that whether it's a ge

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
I don't really disagree with most of what you wrote! And agree that decorators, specifically, are a pretty good solution within the scope of an individual package. But I would quibble with this: >How fundamental is it that THIS function is a generator, rather than simply >that > it returns an