Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vstinner opened this issue Feb 7, 2017 · 5 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Feb 7, 2017

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']

@vstinner
Copy link
Member Author

vstinner commented Feb 7, 2017

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.

@vstinner vstinner added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Feb 7, 2017
@vedgar
Copy link
Mannequin

vedgar mannequin commented Feb 7, 2017

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

@aptrishu
Copy link
Mannequin

aptrishu mannequin commented Mar 3, 2017

I'd like to work on this issue.

@1st1
Copy link
Member

1st1 commented Mar 3, 2017

I'm not sure we need this feature TBH.

@vstinner
Copy link
Member Author

I'm not sure we need this feature TBH.

Ok, I close the issue.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants