Skip to content

Commit 7258576

Browse files
committed
add async context manager methods
1 parent b01544c commit 7258576

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mystbin/client.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
from __future__ import annotations
2424

2525
import datetime
26-
from typing import List, Literal, Optional, Sequence, Union, overload
26+
from types import TracebackType
27+
from typing import List, Literal, Optional, Sequence, Type, Union, overload
2728

2829
import aiohttp
2930

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

45+
async def __aenter__(self):
46+
return self
47+
48+
async def __aexit__(
49+
self,
50+
exc_cls: Optional[Type[BaseException]],
51+
exc_value: Optional[BaseException],
52+
traceback: Optional[TracebackType]
53+
):
54+
await self.close()
55+
4456
async def close(self) -> None:
4557
"""|coro|
4658

0 commit comments

Comments
 (0)