Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/abc/_resources.py: 82%
11 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:12 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:12 +0000
1from abc import ABCMeta, abstractmethod
2from types import TracebackType
3from typing import Optional, Type, TypeVar
5T = TypeVar("T")
8class AsyncResource(metaclass=ABCMeta):
9 """
10 Abstract base class for all closeable asynchronous resources.
12 Works as an asynchronous context manager which returns the instance itself on enter, and calls
13 :meth:`aclose` on exit.
14 """
16 async def __aenter__(self: T) -> T:
17 return self
19 async def __aexit__(
20 self,
21 exc_type: Optional[Type[BaseException]],
22 exc_val: Optional[BaseException],
23 exc_tb: Optional[TracebackType],
24 ) -> None:
25 await self.aclose()
27 @abstractmethod
28 async def aclose(self) -> None:
29 """Close the resource."""