Message287216
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. |
|
Date |
User |
Action |
Args |
2017-02-07 09:08:59 | vstinner | set | recipients:
+ vstinner, methane, yselivanov |
2017-02-07 09:08:59 | vstinner | set | messageid: <1486458539.58.0.744778606798.issue29471@psf.upfronthosting.co.za> |
2017-02-07 09:08:59 | vstinner | link | issue29471 messages |
2017-02-07 09:08:58 | vstinner | create | |
|