-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Clearer error message if async context manager used synchronously #212
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ async def __aiter__(*args, **kwargs): | |
# Copyright © 2001-2017 Python Software Foundation; All Rights Reserved | ||
class _AsyncGeneratorContextManager: | ||
def __init__(self, func, args, kwds): | ||
self._func_name = func.__name__ | ||
self._agen = func(*args, **kwds).__aiter__() | ||
|
||
async def __aenter__(self): | ||
|
@@ -135,6 +136,13 @@ async def __aexit__(self, type, value, traceback): | |
if sys.exc_info()[1] is not value: | ||
raise | ||
|
||
def __enter__(self): | ||
raise RuntimeError("use 'async with {func_name}(...)', not 'with {func_name}(...)'".format(func_name=self._func_name)) | ||
|
||
def __exit__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
assert False, """Never called, but should be defined""" # pragma: no-cover | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be def __exit__(self): # pragma: no cover |
||
|
||
|
||
def acontextmanager(func): | ||
"""Like @contextmanager, but async.""" | ||
if not async_generator.isasyncgenfunction(func): | ||
|
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.
Also needs an extra space before
#
and removal of the-