Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/abc/_resources.py: 85%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3from abc import ABCMeta, abstractmethod
4from types import TracebackType
5from typing import TypeVar
7T = TypeVar("T")
10class AsyncResource(metaclass=ABCMeta):
11 """
12 Abstract base class for all closeable asynchronous resources.
14 Works as an asynchronous context manager which returns the instance itself on enter,
15 and calls :meth:`aclose` on exit.
16 """
18 __slots__ = ()
20 async def __aenter__(self: T) -> T:
21 return self
23 async def __aexit__(
24 self,
25 exc_type: type[BaseException] | None,
26 exc_val: BaseException | None,
27 exc_tb: TracebackType | None,
28 ) -> None:
29 await self.aclose()
31 @abstractmethod
32 async def aclose(self) -> None:
33 """Close the resource."""