Skip to content

Commit 10106ea

Browse files
committed
Fix mypy issues with the latest mypy
This also clarifies some of the typing (i.e. Iterable being required rather than the more specific List).
1 parent 82d7522 commit 10106ea

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

Diff for: example/synchronous_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def wsproto_demo(host: str, port: int) -> None:
7171

7272
# 3) Send ping and display pong
7373
payload = b"table tennis"
74-
print("Sending ping: {}".format(payload))
74+
print("Sending ping: {!r}".format(payload))
7575
net_send(ws.send(Ping(payload=payload)), conn)
7676
net_recv(ws, conn)
7777
handle_events(ws)
@@ -113,7 +113,7 @@ def handle_events(ws: WSConnection) -> None:
113113
elif isinstance(event, TextMessage):
114114
print("Received message: {}".format(event.data))
115115
elif isinstance(event, Pong):
116-
print("Received pong: {}".format(event.payload))
116+
print("Received pong: {!r}".format(event.payload))
117117
else:
118118
raise Exception("Do not know how to handle event: " + str(event))
119119

Diff for: test/test_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_closure(client_sends: bool, code: CloseReason, reason: str) -> None:
7171
assert event.code is code
7272
assert event.reason == reason
7373

74-
assert remote.state is ConnectionState.CLOSED
74+
assert remote.state is ConnectionState.CLOSED # type: ignore
7575
assert local.state is ConnectionState.CLOSED
7676

7777

Diff for: wsproto/handshake.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
An implementation of WebSocket handshakes.
77
"""
88
from collections import deque
9-
from typing import Deque, Dict, Generator, List, Optional, Union
9+
from typing import (
10+
cast,
11+
Deque,
12+
Dict,
13+
Generator,
14+
Iterable,
15+
List,
16+
Optional,
17+
Sequence,
18+
Union,
19+
)
1020

1121
import h11
1222

@@ -268,8 +278,9 @@ def _accept(self, event: AcceptConnection) -> bytes:
268278
)
269279

270280
if event.extensions:
271-
accepts = server_extensions_handshake( # type: ignore
272-
self._initiating_request.extensions, event.extensions
281+
accepts = server_extensions_handshake(
282+
cast(Sequence[str], self._initiating_request.extensions),
283+
event.extensions,
273284
)
274285
if accepts:
275286
headers.append((b"Sec-WebSocket-Extensions", accepts))
@@ -407,8 +418,8 @@ def _establish_client_connection(
407418
"unrecognized subprotocol {}".format(subprotocol),
408419
event_hint=RejectConnection(),
409420
)
410-
extensions = client_extensions_handshake( # type: ignore
411-
accepts, self._initiating_request.extensions
421+
extensions = client_extensions_handshake(
422+
accepts, cast(Sequence[Extension], self._initiating_request.extensions)
412423
)
413424

414425
self._connection = Connection(
@@ -428,7 +439,7 @@ def __repr__(self) -> str:
428439

429440

430441
def server_extensions_handshake(
431-
requested: List[str], supported: List[Extension]
442+
requested: Iterable[str], supported: List[Extension]
432443
) -> Optional[bytes]:
433444
"""Agree on the extensions to use returning an appropriate header value.
434445
@@ -464,7 +475,7 @@ def server_extensions_handshake(
464475

465476

466477
def client_extensions_handshake(
467-
accepted: List[str], supported: List[Extension]
478+
accepted: Iterable[str], supported: Sequence[Extension]
468479
) -> List[Extension]:
469480
# This raises RemoteProtocolError is the accepted extension is not
470481
# supported.

0 commit comments

Comments
 (0)