Issue 29471: AST: add an attribute to FunctionDef to distinguish functions from generators and coroutines (original) (raw)

Issue29471

Created on 2017-02-07 09:08 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg287216 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-02-07 09:08
Currently, symtable_visit_expr() has browse into the AST tree to look up yield, yield from or await to check if a function is a generator or a coroutine. If we choose to start to work on AST optimizers, I would suggest to add an attribute to ast.FunctionDef to announce if a function is a generator or a coroutine. Currently, the peephole optimizer is unable to remove the deadcode, because otherwise the function is no more detected as a generator: def generator(): if 0: yield # "hack" to get a generator pass By the way, it would be nice to add a keyword similar to "async def" to be able to explicitly "document" generators as generators, and avoid the "if 0: yield" hack, but that's a different topic ;-) I feel less confortable to modify the Python language.
msg287221 - (view) Author: Vedran Čačić (veky) * Date: 2017-02-07 09:53
I remember the message from Guido, long time ago when the syntax of generators was discussed. He said he has a hunch that new keyword will not be necessary, that the presence of yield will be enough. It'd be interesting to see if he has changed his mind, or he has some other excuse about async being fundamentally different. :-)
msg288921 - (view) Author: Rishav Kumar (aptrishu) Date: 2017-03-03 20:21
I'd like to work on this issue.
msg288933 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-03 21:27
I'm not sure we need this feature TBH.
msg325827 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-09-19 23:29
> I'm not sure we need this feature TBH. Ok, I close the issue.
History
Date User Action Args
2022-04-11 14:58:42 admin set github: 73657
2018-09-19 23:29:22 vstinner set status: open -> closedresolution: wont fixmessages: + stage: resolved
2017-03-15 06:42:54 mbdevpl set nosy: + mbdevpl
2017-03-03 21:27:06 yselivanov set messages: +
2017-03-03 20:21:40 aptrishu set nosy: + aptrishumessages: +
2017-02-07 09:53:51 veky set nosy: + vekymessages: +
2017-02-07 09:08:59 vstinner create