Skip to content

Update typing hints of timeouts to allow passing floats #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
type_def: Optional[str] = None,
transport: Optional[Union[Transport, AsyncTransport]] = None,
fetch_schema_from_transport: bool = False,
execute_timeout: Optional[int] = 10,
execute_timeout: Optional[Union[int, float]] = 10,
):
"""Initialize the client with the given parameters.

Expand All @@ -57,6 +57,7 @@ def __init__(
the schema from the transport using an introspection query
:param execute_timeout: The maximum time in seconds for the execution of a
request before a TimeoutError is raised. Only used for async transports.
Passing None results in waiting forever for a response.
"""
assert not (
type_def and introspection
Expand Down
34 changes: 16 additions & 18 deletions gql/transport/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def __init__(
headers: Optional[HeadersLike] = None,
ssl: Union[SSLContext, bool] = False,
init_payload: Dict[str, Any] = {},
connect_timeout: int = 10,
close_timeout: int = 10,
ack_timeout: int = 10,
keep_alive_timeout: Optional[int] = None,
connect_timeout: Optional[Union[int, float]] = 10,
close_timeout: Optional[Union[int, float]] = 10,
ack_timeout: Optional[Union[int, float]] = 10,
keep_alive_timeout: Optional[Union[int, float]] = None,
connect_args: Dict[str, Any] = {},
) -> None:
"""Initialize the transport with the given parameters.
Expand All @@ -105,10 +105,11 @@ def __init__(
:param ssl: ssl_context of the connection. Use ssl=False to disable encryption
:param init_payload: Dict of the payload sent in the connection_init message.
:param connect_timeout: Timeout in seconds for the establishment
of the websocket connection.
:param close_timeout: Timeout in seconds for the close.
of the websocket connection. If None is provided this will wait forever.
:param close_timeout: Timeout in seconds for the close. If None is provided
this will wait forever.
:param ack_timeout: Timeout in seconds to wait for the connection_ack message
from the server.
from the server. If None is provided this will wait forever.
:param keep_alive_timeout: Optional Timeout in seconds to receive
a sign of liveness from the server.
:param connect_args: Other parameters forwarded to websockets.connect
Expand All @@ -118,10 +119,10 @@ def __init__(
self.headers: Optional[HeadersLike] = headers
self.init_payload: Dict[str, Any] = init_payload

self.connect_timeout: int = connect_timeout
self.close_timeout: int = close_timeout
self.ack_timeout: int = ack_timeout
self.keep_alive_timeout: Optional[int] = keep_alive_timeout
self.connect_timeout: Optional[Union[int, float]] = connect_timeout
self.close_timeout: Optional[Union[int, float]] = close_timeout
self.ack_timeout: Optional[Union[int, float]] = ack_timeout
self.keep_alive_timeout: Optional[Union[int, float]] = keep_alive_timeout

self.connect_args = connect_args

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

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

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

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

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

async def _wait_ack(self) -> None:
"""Wait for the connection_ack message. Keep alive messages are ignored
"""
"""Wait for the connection_ack message. Keep alive messages are ignored"""

while True:
init_answer = await self._receive()
Expand Down Expand Up @@ -575,7 +573,7 @@ async def connect(self) -> None:
# Set the _connecting flag to False after in all cases
try:
self.websocket = await asyncio.wait_for(
websockets.client.connect(self.url, **connect_args,),
websockets.client.connect(self.url, **connect_args),
self.connect_timeout,
)
finally:
Expand Down