Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 2a499fd

Browse files
authored
Improve types for the SQS store (#13684)
1 parent 706ea55 commit 2a499fd

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

localstack-core/localstack/services/sqs/models.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
class SqsMessage:
5757
message: Message
5858
created: float
59-
visibility_timeout: int
59+
visibility_timeout: int | None
6060
receive_count: int
6161
delay_seconds: int | None
6262
receipt_handles: set[str]
@@ -65,9 +65,7 @@ class SqsMessage:
6565
visibility_deadline: float | None
6666
deleted: bool
6767
priority: float
68-
message_deduplication_id: str
69-
message_group_id: str
70-
sequence_number: str
68+
sequence_number: str | None
7169

7270
def __init__(
7371
self,
@@ -85,6 +83,7 @@ def __init__(
8583
self.delay_seconds = None
8684
self.last_received = None
8785
self.first_received = None
86+
self.visibility_timeout = None
8887
self.visibility_deadline = None
8988
self.deleted = False
9089
self.priority = priority
@@ -270,28 +269,36 @@ class MessageMoveTask:
270269
# configurable fields
271270
source_arn: str
272271
"""The arn of the DLQ the messages are currently in."""
273-
destination_arn: str | None = None
272+
destination_arn: str
274273
"""If the DestinationArn is not specified, the original source arn will be used as target."""
275-
max_number_of_messages_per_second: int | None = None
274+
max_number_of_messages_per_second: int | None
276275

277276
# dynamic fields
278277
task_id: str
279-
status: str = MessageMoveTaskStatus.CREATED
280-
started_timestamp: datetime | None = None
281-
approximate_number_of_messages_moved: int | None = None
282-
approximate_number_of_messages_to_move: int | None = None
283-
failure_reason: str | None = None
278+
status: str
279+
started_timestamp: datetime | None
280+
approximate_number_of_messages_moved: int | None
281+
approximate_number_of_messages_to_move: int | None
282+
failure_reason: str | None
284283

285284
cancel_event: threading.Event
286285

287286
def __init__(
288-
self, source_arn: str, destination_arn: str, max_number_of_messages_per_second: int = None
287+
self,
288+
source_arn: str,
289+
destination_arn: str,
290+
max_number_of_messages_per_second: int | None = None,
289291
):
290292
self.task_id = long_uid()
291293
self.source_arn = source_arn
292294
self.destination_arn = destination_arn
293295
self.max_number_of_messages_per_second = max_number_of_messages_per_second
294296
self.cancel_event = threading.Event()
297+
self.status = MessageMoveTaskStatus.CREATED
298+
self.started_timestamp = None
299+
self.approximate_number_of_messages_moved = None
300+
self.approximate_number_of_messages_to_move = None
301+
self.failure_reason = None
295302

296303
def mark_started(self):
297304
self.started_timestamp = datetime.utcnow()
@@ -318,6 +325,7 @@ class SqsQueue:
318325
# Simulating an ordered set in python. Only the keys are used and of interest.
319326
inflight: dict[SqsMessage, None]
320327
receipts: dict[str, SqsMessage]
328+
mutex: threading.RLock
321329

322330
def __init__(self, name: str, region: str, account_id: str, attributes=None, tags=None) -> None:
323331
self.name = name
@@ -1374,7 +1382,7 @@ def clear(self):
13741382

13751383

13761384
class SqsStore(BaseStore):
1377-
queues: dict[str, SqsQueue] = LocalAttribute(default=dict)
1385+
queues: dict[str, FifoQueue | StandardQueue] = LocalAttribute(default=dict)
13781386

13791387
deleted: dict[str, float] = LocalAttribute(default=dict)
13801388

localstack-core/localstack/services/sqs/queue.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import time
22
from queue import Empty, PriorityQueue, Queue
3+
from typing import Generic, TypeVar
34

5+
T = TypeVar("T")
46

5-
class InterruptibleQueue(Queue):
7+
8+
class InterruptibleQueue(Queue, Generic[T]):
69
# is_shutdown is used to check whether we have triggered a shutdown of the Queue
710
is_shutdown: bool
811

9-
def __init__(self, maxsize=0):
12+
def __init__(self, maxsize: int = 0):
1013
super().__init__(maxsize)
1114
self.is_shutdown = False
1215

13-
def get(self, block=True, timeout=None):
16+
def get(self, block: bool = True, timeout: float | None = None) -> T:
1417
with self.not_empty:
1518
if self.is_shutdown:
1619
raise Empty
@@ -35,7 +38,7 @@ def get(self, block=True, timeout=None):
3538
self.not_full.notify()
3639
return item
3740

38-
def shutdown(self):
41+
def shutdown(self) -> None:
3942
"""
4043
`shutdown` signals to stop all current and future `Queue.get` calls from executing.
4144
@@ -46,5 +49,5 @@ def shutdown(self):
4649
self.not_empty.notify_all()
4750

4851

49-
class InterruptiblePriorityQueue(PriorityQueue, InterruptibleQueue):
52+
class InterruptiblePriorityQueue(PriorityQueue, InterruptibleQueue[T], Generic[T]):
5053
pass

localstack-core/localstack/testing/pytest/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
LOG = logging.getLogger(__name__)
2424

2525
ENV_TEST_CONTAINER_MOUNT_SOURCES = "TEST_CONTAINER_MOUNT_SOURCES"
26-
"""Environment variable used to indicate that we should mount LocalStack source files into the container."""
26+
"""Environment variable used to indicate that we should mount LocalStack source files into the container."""
2727

2828
ENV_TEST_CONTAINER_MOUNT_DEPENDENCIES = "TEST_CONTAINER_MOUNT_DEPENDENCIES"
2929
"""Environment variable used to indicate that we should mount dependencies into the container."""

0 commit comments

Comments
 (0)