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
"yield" causes strange behaviour #45203
Comments
Running the attached files produces: However if you uncomment line 46 and run the file again, you don't get any output. A pdb session of the file produces:
(Sorry for the length of the example, this is the smaller version that still reproduces the bug) |
Miki, I don't see a bug here. The presence of "yield" is significant during compilation not just when the line is executed. When the yield appears anywhere in a function body, it is not a function anymore, it is a generator. So, when the "yield" is uncommented, the call to one_pass returns a generator which doesn't start running until its next() method is called. In contrast, when the "yield" is commented, you have a function that starts running immediately when one_pass() is called. Here is a simplified comparison of the generator versus function: >>> def one_pass():
... print 'running'
... yield 1
...
>>> g = one_pass()
>>> g.next()
running
1
>>> def one_pass():
... print 'running'
... # yield 1
...
>>> one_pass()
running If you still see a bug, please elaborate. If not, please close this report. |
OUCH, forgot about that sorry. Closing. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: