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 generator function or not is fundamental to being able to read it. The type hint alone doesn't tell you whether you're looking at a generator function or not - it might just construct and return an iterator. So, you have to look for a `yield`. And if "yield" is somewhere in the function body, it will abruptly change the semantics of the entire definition. This feels a like spooky-action-at-a-distance to me - I'd much rather have the information up top in the function declaration, the same way that `async def` declares a coroutine function. However: this was actually discussed in PEP 255, where there was a decision *not* to introduce a new keyword for generator functions. From the BDFL decision: > No argument on either side is totally convincing, so I have consulted > my language designer’s intuition. It tells me that the syntax proposed > in the PEP is exactly right - not too hot, not too cold. But, like the Oracle > at Delphi in Greek mythology, it doesn’t tell me why, so I don’t have a > rebuttal for the arguments against the PEP syntax. - Aaron _______________________________________________ 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/MVNK3UJHNFRPQZLHBMV47MLLT5P6OM25/ Code of Conduct: http://python.org/psf/codeofconduct/