-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
asynccontextmanager does not support callable classes #32
Comments
Put
|
I just looked at the linked issue. If you are given the class definition and can't modify it, you could do something like |
Sure, you're recommendation of a workaround makes sense and that's more or less what I did to unblock the python3.6 failure on the MR that I opened for the linked project issue, but I think the functionality that I was trying to call out is slightly different. First, the example was a typo, you are correct that it should be
|
@mrosales fyi this works on the contextlib2 backport: from contextlib2 import asynccontextmanager
class GenClass:
async def __call__(self):
yield "hello"
cm = asynccontextmanager(GenClass())
async def amain():
async with cm() as value:
print(value)
import anyio
anyio.run(amain) |
I was expecting something like the following example to work, but it does not. This originally came up in: fastapi/fastapi#1204
The result is an exception:
The text was updated successfully, but these errors were encountered: