Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/anyio/abc/_resources.py: 82%
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
3import sys
4from abc import ABCMeta, abstractmethod
5from types import TracebackType
6from typing import TypeVar
8if sys.version_info >= (3, 11):
9 from typing import Self
10else:
11 from typing_extensions import Self
13T = TypeVar("T")
16class AsyncResource(metaclass=ABCMeta):
17 """
18 Abstract base class for all closeable asynchronous resources.
20 Works as an asynchronous context manager which returns the instance itself on enter,
21 and calls :meth:`aclose` on exit.
22 """
24 __slots__ = ()
26 async def __aenter__(self) -> Self:
27 return self
29 async def __aexit__(
30 self,
31 exc_type: type[BaseException] | None,
32 exc_val: BaseException | None,
33 exc_tb: TracebackType | None,
34 ) -> None:
35 await self.aclose()
37 @abstractmethod
38 async def aclose(self) -> None:
39 """Close the resource."""