Skip to content

Commit 1e9a75a

Browse files
committed
Lint fixes
1 parent 441bafb commit 1e9a75a

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

src/intersect_sdk/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import time
1616
from collections import defaultdict
1717
from threading import Event, Thread
18-
from typing import TYPE_CHECKING
18+
from typing import TYPE_CHECKING, Any
1919
from uuid import uuid4
2020

2121
from pydantic import ValidationError
@@ -154,7 +154,7 @@ def __init__(
154154
self._user_callback = user_callback
155155
self._event_callback = event_callback
156156
self._timeout_callback = timeout_callback
157-
self._pending_requests: defaultdict[str, list] = defaultdict(list)
157+
self._pending_requests: defaultdict[str, list[dict[str, Any]]] = defaultdict(list)
158158
self._stop_timeout_thread = Event()
159159
self._timeout_thread = Thread(target=self._check_timeouts, daemon=True)
160160

@@ -229,8 +229,10 @@ def _check_timeouts(self) -> None:
229229
if now > request['timeout']:
230230
try:
231231
request['on_timeout'](operation_id)
232-
except Exception as e:
233-
logger.warning(f'Exception from timeout callback for operation {operation_id}:\n{e}')
232+
except Exception as e: # noqa: BLE001
233+
logger.warning(
234+
f'Exception from timeout callback for operation {operation_id}:\n{e}'
235+
)
234236
requests.remove(request)
235237
if not requests:
236238
del self._pending_requests[operation_id]
@@ -293,7 +295,9 @@ def _handle_userspace_message(self, message: UserspaceMessage) -> None:
293295
if message['operationId'] in self._pending_requests:
294296
del self._pending_requests[message['operationId']]
295297
else:
296-
logger.debug(f'Received response for operation {message["operationId"]} that already timed out, ignoring')
298+
logger.debug(
299+
f'Received response for operation {message["operationId"]} that already timed out, ignoring'
300+
)
297301
return
298302

299303
# TWO: GET DATA FROM APPROPRIATE DATA STORE AND DESERIALIZE IT

src/intersect_sdk/client_callback_definitions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .constants import SYSTEM_OF_SYSTEM_REGEX
1212
from .shared_callback_definitions import INTERSECT_JSON_VALUE, IntersectDirectMessageParams
1313

14-
1514
INTERSECT_CLIENT_TIMEOUT_CALLBACK_TYPE = Callable[[str], None]
1615
"""
1716
This is a callable function type which should be defined by the user.

src/intersect_sdk/shared_callback_definitions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Callback definitions shared between Services, Capabilities, and Clients."""
22

3-
from typing import Any, Callable, Dict, List, Optional, Union
3+
from __future__ import annotations
4+
5+
from typing import Any, Callable, Dict, List, Union
46

57
from pydantic import BaseModel, ConfigDict, Field
68
from typing_extensions import Annotated, TypeAlias
@@ -66,12 +68,12 @@ class IntersectDirectMessageParams(BaseModel):
6668
# pydantic config
6769
model_config = ConfigDict(revalidate_instances='always')
6870

69-
timeout: Optional[float] = None
71+
timeout: float | None = None
7072
"""
7173
The timeout in seconds for the request. If the request is not fulfilled within this time, the on_timeout callback will be called.
7274
"""
7375

74-
on_timeout: Optional[Callable[[], None]] = None
76+
on_timeout: Callable[[], None] | None = None
7577
"""
7678
The callback to call if the request times out.
7779
"""

tests/unit/test_client.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import time
44
from threading import Event, Thread
5-
from unittest.mock import MagicMock, patch
6-
7-
import pytest
5+
from unittest.mock import MagicMock
86

97
from intersect_sdk.client import IntersectClient
108
from intersect_sdk.client_callback_definitions import IntersectClientCallback
@@ -18,7 +16,15 @@ def test_timeout_callback_is_called():
1816
system='test',
1917
facility='test',
2018
organization='test',
21-
brokers=[{'host': 'localhost', 'port': 1883, 'protocol': 'mqtt3.1.1', 'username': 'test', 'password': 'test'}],
19+
brokers=[
20+
{
21+
'host': 'localhost',
22+
'port': 1883,
23+
'protocol': 'mqtt3.1.1',
24+
'username': 'test',
25+
'password': 'test',
26+
}
27+
],
2228
initial_message_event_config=IntersectClientCallback(),
2329
terminate_after_initial_messages=True,
2430
)
@@ -72,7 +78,15 @@ def test_timeout_callback_is_not_called():
7278
system='test',
7379
facility='test',
7480
organization='test',
75-
brokers=[{'host': 'localhost', 'port': 1883, 'protocol': 'mqtt3.1.1', 'username': 'test', 'password': 'test'}],
81+
brokers=[
82+
{
83+
'host': 'localhost',
84+
'port': 1883,
85+
'protocol': 'mqtt3.1.1',
86+
'username': 'test',
87+
'password': 'test',
88+
}
89+
],
7690
initial_message_event_config=IntersectClientCallback(),
7791
terminate_after_initial_messages=True,
7892
)
@@ -86,7 +100,6 @@ def on_timeout(operation_id):
86100

87101
def user_callback(source, operation_id, has_error, payload):
88102
user_callback_called.append(True)
89-
return None
90103

91104
client = IntersectClient(config, user_callback=user_callback)
92105

@@ -151,7 +164,15 @@ def test_response_after_timeout_is_ignored():
151164
system='test',
152165
facility='test',
153166
organization='test',
154-
brokers=[{'host': 'localhost', 'port': 1883, 'protocol': 'mqtt3.1.1', 'username': 'test', 'password': 'test'}],
167+
brokers=[
168+
{
169+
'host': 'localhost',
170+
'port': 1883,
171+
'protocol': 'mqtt3.1.1',
172+
'username': 'test',
173+
'password': 'test',
174+
}
175+
],
155176
initial_message_event_config=IntersectClientCallback(),
156177
terminate_after_initial_messages=True,
157178
)
@@ -165,7 +186,6 @@ def on_timeout(operation_id):
165186

166187
def user_callback(source, operation_id, has_error, payload):
167188
user_callback_called.append(True)
168-
return None
169189

170190
client = IntersectClient(config, user_callback=user_callback)
171191

0 commit comments

Comments
 (0)