Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/abc/_resources.py: 83%
12 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:19 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:19 +0000
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, and calls
15 :meth:`aclose` on exit.
16 """
18 async def __aenter__(self: T) -> T:
19 return self
21 async def __aexit__(
22 self,
23 exc_type: type[BaseException] | None,
24 exc_val: BaseException | None,
25 exc_tb: TracebackType | None,
26 ) -> None:
27 await self.aclose()
29 @abstractmethod
30 async def aclose(self) -> None:
31 """Close the resource."""