From 9b3ef85e76cd82250e27cd819d3d1fe2f7797330 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 8 Jul 2022 22:46:04 +0200 Subject: [PATCH] fix context managers --- matrix_alertbot/alertmanager.py | 5 ++--- matrix_alertbot/webhook.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/matrix_alertbot/alertmanager.py b/matrix_alertbot/alertmanager.py index a8e1ec3..fcadf46 100644 --- a/matrix_alertbot/alertmanager.py +++ b/matrix_alertbot/alertmanager.py @@ -16,7 +16,7 @@ from matrix_alertbot.errors import ( ) -class AlertmanagerClient(AsyncContextManager): +class AlertmanagerClient: def __init__(self, url: str, cache: Cache) -> None: self.api_url = f"{url}/api/v2" self.cache = cache @@ -25,8 +25,7 @@ class AlertmanagerClient(AsyncContextManager): async def __aenter__(self) -> AlertmanagerClient: return self - async def __aexit__(self, *args: Any, **kwargs: Any) -> None: - await super().__aexit__(*args, **kwargs) + async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None: await self.close() async def close(self) -> None: diff --git a/matrix_alertbot/webhook.py b/matrix_alertbot/webhook.py index 5a90b22..d098b3d 100644 --- a/matrix_alertbot/webhook.py +++ b/matrix_alertbot/webhook.py @@ -51,7 +51,7 @@ async def create_alert(request: web_request.Request) -> web.Response: return web.Response(status=200) -class Webhook(AsyncContextManager): +class Webhook: def __init__(self, client: AsyncClient, cache: Cache, config: Config) -> None: self.app = web.Application(logger=logger) self.app["client"] = client @@ -68,8 +68,7 @@ class Webhook(AsyncContextManager): async def __aenter__(self) -> Webhook: return self - async def __aexit__(self, *args: Any, **kwargs: Any) -> None: - await super().__aexit__(*args, **kwargs) + async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None: await self.close() async def start(self) -> None: