Author vstinner
Recipients methane, vstinner, yselivanov
Date 2017-02-07.09:08:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486458539.58.0.744778606798.issue29471@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-02-07 09:08:59vstinnersetrecipients: + vstinner, methane, yselivanov
2017-02-07 09:08:59vstinnersetmessageid: <1486458539.58.0.744778606798.issue29471@psf.upfronthosting.co.za>
2017-02-07 09:08:59vstinnerlinkissue29471 messages
2017-02-07 09:08:58vstinnercreate