Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
queue_processors: Fix strict_optional errors.
Anders Kaseorg8e6a439529ba
diff --git a/mypy.ini b/mypy.iniindex e5e98c06b8e..b2afb32246f 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 = Falsediff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.pyindex d133a01e87b..0b06303ab90 100644--- a/zerver/worker/queue_processors.py+++ b/zerver/worker/queue_processors.py@@ -161,12 +161,12 @@ def retry_send_email_failures(return wrapperclass QueueProcessingWorker(ABC):- queue_name: str = None+ queue_name: strCONSUME_ITERATIONS_BEFORE_UPDATE_STATS_NUM = 50def __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 Noneself.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 Noneself.q.stop_consuming()class LoopQueueProcessingWorker(QueueProcessingWorker):@@ -280,6 +282,7 @@ class LoopQueueProcessingWorker(QueueProcessingWorker):sleep_only_if_empty = Truedef start(self) -> None: # nocoverage+ assert self.q is not Noneself.initialize_statistics()while True:events = self.q.json_drain_queue(self.queue_name)