Skip to content

Commit

Permalink
add async context manager methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ika2kki committed Jan 11, 2024
1 parent b01544c commit 7258576
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mystbin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from __future__ import annotations

import datetime
from typing import List, Literal, Optional, Sequence, Union, overload
from types import TracebackType
from typing import List, Literal, Optional, Sequence, Type, Union, overload

import aiohttp

Expand All @@ -41,6 +42,17 @@ class Client:
def __init__(self, *, token: Optional[str] = None, session: Optional[aiohttp.ClientSession] = None) -> None:
self.http: HTTPClient = HTTPClient(token=token, session=session)

async def __aenter__(self):
return self

async def __aexit__(
self,
exc_cls: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]
):
await self.close()

async def close(self) -> None:
"""|coro|
Expand Down

0 comments on commit 7258576

Please sign in to comment.