Typing and Generics
typing.AsyncContextManager
An asynchronous context manager whose aenter result is T. Python 3.13 adds an optional exit return type parameter defaulting to bool | None. Deprecated typing alias; prefer contextlib.AbstractAsyncContextManager in modern code (3.9+).
Formal Syntax & Structure
python syntaxpython
typing.AsyncContextManager[T, ExitT]Return Value
type expression
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import AsyncContextManager
import asynciofrom contextlib import asynccontextmanager@asynccontextmanagerasync def resource(): yield "ok"async def read(manager:AsyncContextManager[str])->str: async with manager as value: return valueasync def main(): return await read(resource())print(asyncio.run(main()))