Skip to content

Commit 4d3b1cc

Browse files
bluetechpgjones
authored andcommitted
Add type annotations to example and check it in CI
1 parent bfa44fe commit 4d3b1cc

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

example/synchronous_client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
RECEIVE_BYTES = 4096
2323

2424

25-
def main():
25+
def main() -> None:
2626
"""Run the client."""
2727
try:
2828
host = sys.argv[1]
@@ -37,7 +37,7 @@ def main():
3737
print("\nReceived SIGINT: shutting down…")
3838

3939

40-
def wsproto_demo(host, port):
40+
def wsproto_demo(host: str, port: int) -> None:
4141
"""
4242
Demonstrate wsproto:
4343
@@ -46,8 +46,6 @@ def wsproto_demo(host, port):
4646
2) Send a message and display response
4747
3) Send ping and display pong
4848
4) Negotiate WebSocket closing handshake
49-
50-
:param stream: a socket stream
5149
"""
5250

5351
# 0) Open TCP connection
@@ -89,13 +87,13 @@ def wsproto_demo(host, port):
8987
net_recv(ws, conn)
9088

9189

92-
def net_send(out_data, conn):
90+
def net_send(out_data: bytes, conn: socket.socket) -> None:
9391
""" Write pending data from websocket to network. """
9492
print("Sending {} bytes".format(len(out_data)))
9593
conn.send(out_data)
9694

9795

98-
def net_recv(ws, conn):
96+
def net_recv(ws: WSConnection, conn: socket.socket) -> None:
9997
""" Read pending data from network into websocket. """
10098
in_data = conn.recv(RECEIVE_BYTES)
10199
if not in_data:
@@ -108,7 +106,7 @@ def net_recv(ws, conn):
108106
ws.receive_data(in_data)
109107

110108

111-
def handle_events(ws):
109+
def handle_events(ws: WSConnection) -> None:
112110
for event in ws.events():
113111
if isinstance(event, AcceptConnection):
114112
print("WebSocket negotiation complete")

example/synchronous_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
RECEIVE_BYTES = 4096
2323

2424

25-
def main():
25+
def main() -> None:
2626
"""Run the server."""
2727
try:
2828
ip = sys.argv[1]
@@ -48,7 +48,7 @@ def main():
4848
print("Received SIGINT: shutting down…")
4949

5050

51-
def handle_connection(stream):
51+
def handle_connection(stream: socket.socket) -> None:
5252
"""
5353
Handle a connection.
5454
@@ -80,8 +80,8 @@ def handle_connection(stream):
8080
elif isinstance(event, CloseConnection):
8181
# Print log message and break out
8282
print(
83-
"Connection closed: code={}/{} reason={}".format(
84-
event.code.value, event.code.name, event.reason
83+
"Connection closed: code={} reason={}".format(
84+
event.code, event.reason
8585
)
8686
)
8787
out_data += ws.send(event.response())

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ commands =
3636
basepython = python3.7
3737
deps = mypy
3838
commands =
39-
mypy wsproto/ test/
39+
mypy wsproto/ test/ example/
4040

4141
[testenv:lint]
4242
basepython = python3.6

0 commit comments

Comments
 (0)