Skip to content

Commit 1ba0683

Browse files
committed
Older 'Union' type hint is still needed in Python 3.9, oops
1 parent 0907d7b commit 1ba0683

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/murfey/server/websocket.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import logging
66
from datetime import datetime
7-
from typing import Any, TypeVar
7+
from typing import Any, TypeVar, Union
88

99
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
1010
from sqlmodel import Session, select
@@ -22,10 +22,13 @@
2222

2323
class ConnectionManager:
2424
def __init__(self):
25-
self.active_connections: dict[int | str, WebSocket] = {}
25+
self.active_connections: dict[Union[int, str], WebSocket] = {}
2626

2727
async def connect(
28-
self, websocket: WebSocket, client_id: int | str, register_client: bool = True
28+
self,
29+
websocket: WebSocket,
30+
client_id: Union[int, str],
31+
register_client: bool = True,
2932
):
3033
await websocket.accept()
3134
self.active_connections[client_id] = websocket
@@ -45,7 +48,7 @@ def _register_new_client(client_id: int):
4548
murfey_db.commit()
4649
murfey_db.close()
4750

48-
def disconnect(self, client_id: int | str, unregister_client: bool = True):
51+
def disconnect(self, client_id: Union[int, str], unregister_client: bool = True):
4952
self.active_connections.pop(client_id)
5053
if unregister_client:
5154
murfey_db: Session = next(get_murfey_db_session())
@@ -94,7 +97,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
9497
@ws.websocket("/connect/{client_id}")
9598
async def websocket_connection_endpoint(
9699
websocket: WebSocket,
97-
client_id: int | str,
100+
client_id: Union[int, str],
98101
):
99102
await manager.connect(websocket, client_id, register_client=False)
100103
await manager.broadcast(f"Client {client_id} joined")
@@ -158,7 +161,7 @@ async def close_ws_connection(client_id: int):
158161

159162

160163
@ws.delete("/connect/{client_id}")
161-
async def close_unrecorded_ws_connection(client_id: int | str):
164+
async def close_unrecorded_ws_connection(client_id: Union[int, str]):
162165
client_id_str = str(client_id).replace("\r\n", "").replace("\n", "")
163166
log.info(f"Disconnecting {client_id_str}")
164167
manager.disconnect(client_id)

0 commit comments

Comments
 (0)