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

2022-06-01 Thread Stephen J. Turnbull
Serhiy Storchaka writes: > The advantage is that you cannot accidentally turn a function into a > generator by adding "yield". Can't mypy catch this? > Asynchronous functions are more reliable. "async" is mandatory, and if > you do not await the result of an asynchronous function call you

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

2022-06-01 Thread Serhiy Storchaka
01.06.22 16:59, Chris Angelico пише: On Wed, 1 Jun 2022 at 23:55, Serhiy Storchaka wrote: The advantage is that you cannot accidentally turn a function into a generator by adding "yield". If the result of the call is ignored (it is expected to be None), this bug can live a long time. It is a co

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

2022-06-01 Thread Eric V. Smith
On 6/1/2022 9:59 AM, Chris Angelico wrote: On Wed, 1 Jun 2022 at 23:55, Serhiy Storchaka wrote: 31.05.22 16:21, Chris Angelico пише: On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas wrote: After getting used to writing async functions, I’ve been wanting use a similar syntax to declare

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

2022-06-01 Thread Chris Angelico
On Wed, 1 Jun 2022 at 23:55, Serhiy Storchaka wrote: > > 31.05.22 16:21, Chris Angelico пише: > > On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas > > wrote: > >> After getting used to writing async functions, I’ve been wanting use a > >> similar syntax to declare generator functions. > >

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

2022-06-01 Thread Serhiy Storchaka
31.05.22 16:21, Chris Angelico пише: On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas wrote: After getting used to writing async functions, I’ve been wanting use a similar syntax to declare generator functions. What's the advantage? You can just use normal function syntax to define the

[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

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

2022-05-31 Thread Chris Angelico
On Wed, 1 Jun 2022 at 03:34, Aaron L via Python-ideas wrote: > > 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 li

[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 Chris Angelico
On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas 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