Skip to content

AST: add an attribute to FunctionDef to distinguish functions from generators and coroutines #73657

Closed

Description

@vstinner
BPO 29471
Nosy @vstinner, @methane, @1st1, @vedgar, @aptrishu, @mbdevpl

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2018-09-19.23:29:22.395>
created_at = <Date 2017-02-07.09:08:59.541>
labels = ['interpreter-core', 'type-feature', '3.7']
title = 'AST: add an attribute to FunctionDef to distinguish functions from generators and coroutines'
updated_at = <Date 2018-09-19.23:29:22.393>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2018-09-19.23:29:22.393>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2018-09-19.23:29:22.395>
closer = 'vstinner'
components = ['Interpreter Core']
creation = <Date 2017-02-07.09:08:59.541>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 29471
keywords = []
message_count = 5.0
messages = ['287216', '287221', '288921', '288933', '325827']
nosy_count = 6.0
nosy_names = ['vstinner', 'methane', 'yselivanov', 'veky', 'aptrishu', 'mbdevpl']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue29471'
versions = ['Python 3.7']

Activity

  1. vstinner commented on Feb 7, 2017

    @vstinner
    MemberAuthor

    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.

  2. vedgar commented on Feb 7, 2017

    vedgarmannequin
    Mannequin

    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. :-)

  3. aptrishu commented on Mar 3, 2017

    aptrishumannequin
    Mannequin

    I'd like to work on this issue.

  4. 1st1 commented on Mar 3, 2017

    @1st1
    Member

    I'm not sure we need this feature TBH.

  5. vstinner commented on Sep 19, 2018

    @vstinner
    MemberAuthor

    I'm not sure we need this feature TBH.

    Ok, I close the issue.

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.7 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions