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
AsyncIterator on 3.7: __aiter__ no longer honors finally blocks #80584
Comments
We use finally blocks in
Attached is a test for both iterators and async iterators. Thanks for your attention! This worked perfectly well in Python 3.6, but stopped working in Python 3.7. I also verified that Iterator supports the same construct (and this works in both Python 3.6 and 3.7):
|
The attached script fails on master too. On bisecting could this be possibly caused due to 41e5ec3 (bpo-34769) ? Tagging Ned since it was introduced from 3.7.1rc2 and also backported to 3.6 . ➜ cpython git:(41e5ec3) git checkout 41e5ec3 && make -s -j4 > /dev/null Traceback (most recent call last):
File "../backups/bpo36403.py", line 30, in test_main
self.assertTrue(it.finally_executed)
AssertionError: False is not true Ran 2 tests in 0.002s FAILED (failures=1) OK |
Ah, so the extra call_soon means it needs a: [code] before the self.assertTrue(it.finally_executed) to finish executing agen.close(). Why is create_task different? Does it execute an iteration of the generator immediately? Seems good for this behavior to be consistent, but not sure how difficult that would be.
|
Perhaps we could add a self._finally to the event loop itself? |
Ping. This was marked as a 3.7regression. Is a change needed? |
From my understanding yield inside __aiter__ is a forbidden construction. Even if parser allows it the statement doesn't make any sense. I'm very interested to hear Yuri opinion. |
I note this is marked as a 3.7regression and still open. Since the cutoff for the final 3.7 bugfix mode release is in a few days, I'm assuming this means that 3.7 users will have to live with this regression. If you feel that is a problem, speak up now. |
I don't see how this is a bug or regression. There is no guarantee when generators are finalized, code relying on it is already subtly broken. I'll close this unless anyone objects, marking pending. |
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: