
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 will get a loud warning.
"yield" is mandatory in generators, and it should be possible to detect if a generator is called other than in an iteration context (and possibly we would want to special-case functions like 'dir', 'help', and 'type' for this purpose). As far as the signature goes, I would suppose -> GeneratorType (or GeneratorType[T] if you know the type of object to be yielded) would clue folks in, and mypy could warn if it were missing. Sure, you would like to have the guarantees of mandatory syntax, but (unless I'm missing something) we can do this now. Steve