Add AsyncContextManager as Parent Class to BaseUpdateProcessor (#4001)

This commit is contained in:
Bibo-Joshi 2023-12-13 20:22:10 +01:00 committed by GitHub
parent fd6a0fe899
commit cc45f49a4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,10 +20,12 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from asyncio import BoundedSemaphore from asyncio import BoundedSemaphore
from types import TracebackType from types import TracebackType
from typing import Any, Awaitable, Optional, Type, final from typing import Any, AsyncContextManager, Awaitable, Optional, Type, TypeVar, final
_BUPT = TypeVar("_BUPT", bound="BaseUpdateProcessor")
class BaseUpdateProcessor(ABC): class BaseUpdateProcessor(AsyncContextManager["BaseUpdateProcessor"], ABC):
"""An abstract base class for update processors. You can use this class to implement """An abstract base class for update processors. You can use this class to implement
your own update processor. your own update processor.
@ -67,7 +69,7 @@ class BaseUpdateProcessor(ABC):
raise ValueError("`max_concurrent_updates` must be a positive integer!") raise ValueError("`max_concurrent_updates` must be a positive integer!")
self._semaphore = BoundedSemaphore(self.max_concurrent_updates) self._semaphore = BoundedSemaphore(self.max_concurrent_updates)
async def __aenter__(self) -> "BaseUpdateProcessor": async def __aenter__(self: _BUPT) -> _BUPT: # noqa: PYI019
"""|async_context_manager| :meth:`initializes <initialize>` the Processor. """|async_context_manager| :meth:`initializes <initialize>` the Processor.
Returns: Returns: