Skip to content

Commit e1e0c3c

Browse files
committed
fix(gql.transport.websockets): update type to permit passing floats
1 parent 87a56ce commit e1e0c3c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

gql/transport/websockets.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ def __init__(
9292
headers: Optional[HeadersLike] = None,
9393
ssl: Union[SSLContext, bool] = False,
9494
init_payload: Dict[str, Any] = {},
95-
connect_timeout: int = 10,
96-
close_timeout: int = 10,
97-
ack_timeout: int = 10,
98-
keep_alive_timeout: Optional[int] = None,
95+
connect_timeout: Optional[Union[int, float]] = 10,
96+
close_timeout: Optional[Union[int, float]] = 10,
97+
ack_timeout: Optional[Union[int, float]] = 10,
98+
keep_alive_timeout: Optional[Union[int, float]] = None,
9999
connect_args: Dict[str, Any] = {},
100100
) -> None:
101101
"""Initialize the transport with the given parameters.
@@ -105,10 +105,11 @@ def __init__(
105105
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
106106
:param init_payload: Dict of the payload sent in the connection_init message.
107107
:param connect_timeout: Timeout in seconds for the establishment
108-
of the websocket connection.
109-
:param close_timeout: Timeout in seconds for the close.
108+
of the websocket connection. If None is provided this will wait forever.
109+
:param close_timeout: Timeout in seconds for the close. If None is provided
110+
this will wait forever.
110111
:param ack_timeout: Timeout in seconds to wait for the connection_ack message
111-
from the server.
112+
from the server. If None is provided this will wait forever.
112113
:param keep_alive_timeout: Optional Timeout in seconds to receive
113114
a sign of liveness from the server.
114115
:param connect_args: Other parameters forwarded to websockets.connect
@@ -118,10 +119,10 @@ def __init__(
118119
self.headers: Optional[HeadersLike] = headers
119120
self.init_payload: Dict[str, Any] = init_payload
120121

121-
self.connect_timeout: int = connect_timeout
122-
self.close_timeout: int = close_timeout
123-
self.ack_timeout: int = ack_timeout
124-
self.keep_alive_timeout: Optional[int] = keep_alive_timeout
122+
self.connect_timeout: Optional[Union[int, float]] = connect_timeout
123+
self.close_timeout: Optional[Union[int, float]] = close_timeout
124+
self.ack_timeout: Optional[Union[int, float]] = ack_timeout
125+
self.keep_alive_timeout: Optional[Union[int, float]] = keep_alive_timeout
125126

126127
self.connect_args = connect_args
127128

@@ -156,8 +157,7 @@ def __init__(
156157
self.close_exception: Optional[Exception] = None
157158

158159
async def _send(self, message: str) -> None:
159-
"""Send the provided message to the websocket connection and log the message
160-
"""
160+
"""Send the provided message to the websocket connection and log the message"""
161161

162162
if not self.websocket:
163163
raise TransportClosed(
@@ -172,8 +172,7 @@ async def _send(self, message: str) -> None:
172172
raise e
173173

174174
async def _receive(self) -> str:
175-
"""Wait the next message from the websocket connection and log the answer
176-
"""
175+
"""Wait the next message from the websocket connection and log the answer"""
177176

178177
# It is possible that the websocket has been already closed in another task
179178
if self.websocket is None:
@@ -194,8 +193,7 @@ async def _receive(self) -> str:
194193
return answer
195194

196195
async def _wait_ack(self) -> None:
197-
"""Wait for the connection_ack message. Keep alive messages are ignored
198-
"""
196+
"""Wait for the connection_ack message. Keep alive messages are ignored"""
199197

200198
while True:
201199
init_answer = await self._receive()
@@ -575,7 +573,7 @@ async def connect(self) -> None:
575573
# Set the _connecting flag to False after in all cases
576574
try:
577575
self.websocket = await asyncio.wait_for(
578-
websockets.client.connect(self.url, **connect_args,),
576+
websockets.client.connect(self.url, **connect_args),
579577
self.connect_timeout,
580578
)
581579
finally:

0 commit comments

Comments
 (0)