Skip to content

Commit a6bc7df

Browse files
committed
use contextlib abstract base classes
1 parent 0a43113 commit a6bc7df

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

src/lpdb_python/async_session/async_session.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import AbstractAsyncContextManager
12
from datetime import date
23
from types import TracebackType
34
from typing import Any, Literal, Optional, override
@@ -9,7 +10,7 @@
910
__all__ = ["AsyncLpdbSession"]
1011

1112

12-
class AsyncLpdbSession(AbstractLpdbSession):
13+
class AsyncLpdbSession(AbstractLpdbSession, AbstractAsyncContextManager):
1314
"""
1415
Asynchronous implementation of a LPDB session
1516
"""
@@ -33,9 +34,6 @@ def __exit__(
3334
) -> None:
3435
pass
3536

36-
async def __aenter__(self) -> "AsyncLpdbSession":
37-
return self
38-
3937
async def __aexit__(
4038
self,
4139
exc_type: Optional[type[BaseException]],

src/lpdb_python/session.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import abstractmethod, ABC
2+
from contextlib import AbstractContextManager
23
from datetime import date
34
from functools import cache
45
from http import HTTPStatus
@@ -318,7 +319,7 @@ def _parse_results(
318319
return result
319320

320321

321-
class LpdbSession(AbstractLpdbSession):
322+
class LpdbSession(AbstractLpdbSession, AbstractContextManager):
322323
"""
323324
Implementation of a LPDB session
324325
"""
@@ -330,9 +331,6 @@ def __init__(self, api_key: str, base_url=AbstractLpdbSession.BASE_URL):
330331
self.__session = requests.Session()
331332
self.__session.headers.update(self._get_header())
332333

333-
def __enter__(self) -> "LpdbSession":
334-
return self
335-
336334
def __exit__(
337335
self,
338336
exc_type: Optional[type[BaseException]],

0 commit comments

Comments
 (0)