Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy committed Oct 28, 2024
1 parent e187118 commit 0dfb5cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions tests/unit/vendor/httpx_ws/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ def __enter__(self) -> "WebSocketSession":

return self

def __exit__(self, exc_type, exc, tb):
def __exit__(
self,
exc_type: typing.Optional[type[BaseException]],
exc: typing.Optional[BaseException],
tb: typing.Optional[TracebackType],
) -> None:
self.close()
self._background_receive_task.join()
if self._background_keepalive_ping_task is not None:
Expand Down Expand Up @@ -416,7 +421,7 @@ def receive_json(
data = self.receive_bytes(timeout)
return json.loads(data)

def close(self, code: int = 1000, reason: typing.Optional[str] = None):
def close(self, code: int = 1000, reason: typing.Optional[str] = None) -> None:
"""
Close the WebSocket session.
Expand Down Expand Up @@ -522,7 +527,7 @@ def _background_keepalive_ping(
pass

def _wait_until_closed(
self, callable: typing.Callable[..., TaskResult], *args, **kwargs
self, callable: typing.Callable[..., TaskResult], *args: typing.Any, **kwargs: typing.Any
) -> TaskResult:
try:
executor, should_close_task = self._get_executor_should_close_task()
Expand Down Expand Up @@ -921,7 +926,7 @@ async def receive_json(
data = await self.receive_bytes(timeout)
return json.loads(data)

async def close(self, code: int = 1000, reason: typing.Optional[str] = None):
async def close(self, code: int = 1000, reason: typing.Optional[str] = None) -> None:
"""
Close the WebSocket session.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/vendor/httpx_ws/_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create(self, ping_id: typing.Optional[bytes] = None) -> tuple[bytes, threadi
self._pings[ping_id] = event
return ping_id, event

def ack(self, ping_id: typing.Union[bytes, bytearray]):
def ack(self, ping_id: typing.Union[bytes, bytearray]) -> None:
event = self._pings.pop(bytes(ping_id))
event.set()

Expand All @@ -35,6 +35,6 @@ def create(self, ping_id: typing.Optional[bytes] = None) -> tuple[bytes, anyio.E
self._pings[ping_id] = event
return ping_id, event

def ack(self, ping_id: typing.Union[bytes, bytearray]):
def ack(self, ping_id: typing.Union[bytes, bytearray]) -> None:
event = self._pings.pop(bytes(ping_id))
event.set()
6 changes: 3 additions & 3 deletions tests/unit/vendor/httpx_ws/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, app: ASGIApp, scope: Scope) -> None:
self._send_queue: asyncio.Queue[Message] = asyncio.Queue()
self.connection = wsproto.WSConnection(wsproto.ConnectionType.SERVER)
self.connection.initiate_upgrade_connection(scope["headers"], scope["path"])
self.tasks: list[asyncio.Task] = []
self.tasks: list[asyncio.Task[None]] = []

async def __aenter__(
self,
Expand All @@ -65,7 +65,7 @@ async def __aexit__(self, *args: typing.Any) -> None:
await self.aclose()
await self.exit_stack.aclose()

async def _cancel_tasks(self):
async def _cancel_tasks(self) -> None:
# Cancel all running tasks
for task in self.tasks:
task.cancel()
Expand Down Expand Up @@ -166,7 +166,7 @@ def _build_accept_response(self, message: Message) -> bytes:


class ASGIWebSocketTransport(ASGITransport):
def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
super().__init__(*args, **kwargs)
self.exit_stack: typing.Optional[contextlib.AsyncExitStack] = None

Expand Down

0 comments on commit 0dfb5cc

Please sign in to comment.