This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients methane, vstinner, yselivanov
Date 2017-02-07.09:08:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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

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:59vstinnersetrecipients: + vstinner, methane, yselivanov
2017-02-07 09:08:59vstinnersetmessageid: <>
2017-02-07 09:08:59vstinnerlinkissue29471 messages
2017-02-07 09:08:58vstinnercreate