66An implementation of WebSocket handshakes.
77"""
88from 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
1121import 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
430441def 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
466477def 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