Skip to content

Commit c0b97a5

Browse files
Add explicit context manager type hints to clients
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 21ad96f commit c0b97a5

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

hyperbrowser/client/async_client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Mapping, Optional
1+
from types import TracebackType
2+
from typing import Mapping, Optional, Type
23

34
from ..config import ClientConfig
45
from ..transport.async_transport import AsyncTransport
@@ -44,8 +45,13 @@ def __init__(
4445
async def close(self) -> None:
4546
await self.transport.close()
4647

47-
async def __aenter__(self):
48+
async def __aenter__(self) -> "AsyncHyperbrowser":
4849
return self
4950

50-
async def __aexit__(self, exc_type, exc_val, exc_tb):
51+
async def __aexit__(
52+
self,
53+
exc_type: Optional[Type[BaseException]],
54+
exc_val: Optional[BaseException],
55+
exc_tb: Optional[TracebackType],
56+
) -> None:
5157
await self.close()

hyperbrowser/client/sync.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Mapping, Optional
1+
from types import TracebackType
2+
from typing import Mapping, Optional, Type
23

34
from ..config import ClientConfig
45
from ..transport.sync import SyncTransport
@@ -44,8 +45,13 @@ def __init__(
4445
def close(self) -> None:
4546
self.transport.close()
4647

47-
def __enter__(self):
48+
def __enter__(self) -> "Hyperbrowser":
4849
return self
4950

50-
def __exit__(self, exc_type, exc_val, exc_tb):
51+
def __exit__(
52+
self,
53+
exc_type: Optional[Type[BaseException]],
54+
exc_val: Optional[BaseException],
55+
exc_tb: Optional[TracebackType],
56+
) -> None:
5157
self.close()

0 commit comments

Comments
 (0)