diff --git a/rq/cli/cli.py b/rq/cli/cli.py index 1954400bc..0d53ccbc3 100755 --- a/rq/cli/cli.py +++ b/rq/cli/cli.py @@ -7,7 +7,7 @@ import os import sys import warnings -from typing import List, Type +from typing import TYPE_CHECKING, List, Type, cast import click from redis.exceptions import ConnectionError @@ -48,6 +48,9 @@ from rq.worker_pool import WorkerPool from rq.worker_registration import clean_worker_registry +if TYPE_CHECKING: + from rq.serializers import Serializer + @click.group() @click.version_option(version) @@ -461,7 +464,7 @@ def worker_pool( setup_loghandlers_from_args(verbose, quiet, date_format, log_format) if serializer: - serializer_class: Type[DefaultSerializer] = import_attribute(serializer) # type: ignore[assignment] + serializer_class = cast(Type['Serializer'], import_attribute(serializer)) else: serializer_class = DefaultSerializer diff --git a/rq/worker_pool.py b/rq/worker_pool.py index 727c74009..900b7b9b8 100644 --- a/rq/worker_pool.py +++ b/rq/worker_pool.py @@ -60,7 +60,7 @@ def __init__( self._sleep: int = 0 self.status: self.Status = self.Status.IDLE # type: ignore self.worker_class: Type[BaseWorker] = worker_class - self.serializer: Type[DefaultSerializer] = serializer + self.serializer: Type['Serializer'] = serializer self.job_class: Type[Job] = job_class # A dictionary of WorkerData keyed by worker name @@ -247,7 +247,7 @@ def run_worker( connection_pool_class, connection_pool_kwargs: dict, worker_class: Type[BaseWorker] = Worker, - serializer: Type[DefaultSerializer] = DefaultSerializer, + serializer: Type['Serializer'] = DefaultSerializer, job_class: Type[Job] = Job, burst: bool = True, logging_level: str = "INFO",