diff --git a/mypy.ini b/mypy.ini index e5e98c06b8..b2afb32246 100644 --- a/mypy.ini +++ b/mypy.ini @@ -40,8 +40,6 @@ strict_optional = True # General exclusions to work on -[mypy-zerver.worker.queue_processors] -strict_optional = False [mypy-zerver.views.registration] strict_optional = False diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index d133a01e87..0b06303ab9 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -161,12 +161,12 @@ def retry_send_email_failures( return wrapper class QueueProcessingWorker(ABC): - queue_name: str = None + queue_name: str CONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM = 50 def __init__(self) -> None: - self.q: SimpleQueueClient = None - if self.queue_name is None: + self.q: Optional[SimpleQueueClient] = None + if not hasattr(self, "queue_name"): raise WorkerDeclarationException("Queue worker declared without queue_name") self.initialize_statistics() @@ -268,11 +268,13 @@ class QueueProcessingWorker(ABC): self.q = SimpleQueueClient() def start(self) -> None: + assert self.q is not None self.initialize_statistics() self.q.register_json_consumer(self.queue_name, self.consume_wrapper) self.q.start_consuming() def stop(self) -> None: # nocoverage + assert self.q is not None self.q.stop_consuming() class LoopQueueProcessingWorker(QueueProcessingWorker): @@ -280,6 +282,7 @@ class LoopQueueProcessingWorker(QueueProcessingWorker): sleep_only_if_empty = True def start(self) -> None: # nocoverage + assert self.q is not None self.initialize_statistics() while True: events = self.q.json_drain_queue(self.queue_name)