Skip to content

asynccontextmanager does not support callable classes #32

@mrosales

Description

@mrosales

I was expecting something like the following example to work, but it does not. This originally came up in: fastapi/fastapi#1204

from async_generator import asynccontextmanager

class GenClass:
    async def __call__(self):
        yield "hello"


cm = asynccontextmanager(GenClass())

with cm as value:
    print(value)

The result is an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../lib/python3.6/site-packages/async_generator/_util.py", line 100, in asynccontextmanager
    "must be an async generator (native or from async_generator; "
TypeError: must be an async generator (native or from async_generator; if using @async_generator then @acontextmanager must be on top.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions