On this page
  1. contextlib.AbstractAsyncContextManager
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

contextlib.AbstractAsyncContextManager

Up: contextlib | Next: contextlib.AbstractContextManager
Rel: contextlib.AbstractContextManager, contextlib.aclosing, contextlib.asynccontextmanager, contextlib.AsyncExitStack
Ref: docs.python.org — contextlib.AbstractAsyncContextManager
Tags: #public #python3 #stdlib #contextlib


Import

import contextlib
from contextlib import AbstractAsyncContextManager

Signature & Overview

contextlib.AbstractAsyncContextManager()

An abstract base class for asynchronous context managers.

Usage

import asyncio
from contextlib import AbstractAsyncContextManager

class AsyncSession(AbstractAsyncContextManager):
    async def __aenter__(self):
        return "session-open"
    async def __aexit__(self, exc_type, exc, tb):
        return False

async def main():
    async with AsyncSession() as s:
        assert s == "session-open"

asyncio.run(main())

Gotchas

REPL Inspect

from contextlib import AbstractAsyncContextManager
help(AbstractAsyncContextManager)

Linked from

Related notes