You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if this is intentional, but contextlib's asynccontextmanager decorated functions return None whereas here they'd return False. The snippet below shows that:
import asyncio
import contextlib
from async_generator import asynccontextmanager
@contextlib.asynccontextmanager
async def f():
yield
@asynccontextmanager
async def g():
yield
async def main():
ctx1 = f()
ctx2 = g()
await asyncio.gather(*(ctx.__aenter__() for ctx in [ctx1, ctx2]))
exits = await asyncio.gather(*(ctx.__aexit__(None, None, None) for ctx in [ctx1, ctx2]))
print(exits)
l = asyncio.get_event_loop()
l.run_until_complete(main())
The text was updated successfully, but these errors were encountered:
Both approaches adhere to the context manager protocol, since both returns test as false. Are you running into an issue where the difference is relevant to your application?
It looks like the synchronous @contextlib.contextmanager returns False in this case, which is where async_generator got its behavior from. And @contextlib.asynccontextmanager returns False in some cases and None in others. I think the stdlib @asynccontextmanager is the odd one out here.
Not really relevant to my application, but I was writing some tests that checked for the yielded values and noticed the discrepancy so I thought maybe it was worth reporting. Feel free to ignoreclose if you think it has no practical implications
I don't know if this is intentional, but contextlib's
asynccontextmanager
decorated functions return None whereas here they'd return False. The snippet below shows that:The text was updated successfully, but these errors were encountered: