-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-110378: Close invalid generators in contextmanager and asynccontextmanager #110499
gh-110378: Close invalid generators in contextmanager and asynccontextmanager #110499
Conversation
…contextmanager contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value.
try: | ||
raise RuntimeError("generator didn't stop") | ||
finally: | ||
self.gen.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
I sometimes use the try:finally:
construct around flow breaking instructions as well. Here it nicely chains exceptions if self.gen.close()
raises.
Thanks @serhiy-storchaka for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…contextmanager (pythonGH-110499) contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value. (cherry picked from commit 96fed66) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…contextmanager (pythonGH-110499) contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value. (cherry picked from commit 96fed66) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-110588 is a backport of this pull request to the 3.12 branch. |
GH-110589 is a backport of this pull request to the 3.11 branch. |
…ccontextmanager (GH-110499) (#110589) contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value. (cherry picked from commit 96fed66) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
…contextmanager (pythonGH-110499) contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value.
contextmanager and asynccontextmanager context managers now close an invalid underlying generator object that yields more then one value.
test_contextlib_async
produces severalRuntimeWarning
s #110378