From c0f29785cdb54a187d4e596bc8003cf57a83e432 Mon Sep 17 00:00:00 2001 From: yogeshwaran-c Date: Tue, 28 Apr 2026 18:22:54 +0530 Subject: [PATCH 1/2] feat(python): add type hints to utils functions --- python/bullmq/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/bullmq/utils.py b/python/bullmq/utils.py index d60693fdb80..2a281a9dd46 100644 --- a/python/bullmq/utils.py +++ b/python/bullmq/utils.py @@ -1,15 +1,16 @@ +import asyncio import json import traceback -from typing import Any +from typing import Any, Callable, Optional import semver -def isRedisVersionLowerThan(current_version, minimum_version): +def isRedisVersionLowerThan(current_version: str, minimum_version: str) -> bool: return semver.Version.parse(current_version).compare(minimum_version) == -1 -def extract_result(job_task, emit_callback): +def extract_result(job_task: asyncio.Task, emit_callback: Callable[[str, Any], None]) -> Any: try: return job_task.result() except Exception as e: @@ -19,7 +20,7 @@ def extract_result(job_task, emit_callback): traceback.print_exc() emit_callback("error", e) -def get_parent_key(opts: dict[str, str]): +def get_parent_key(opts: dict[str, str]) -> Optional[str]: if opts: return f"{opts.get('queue')}:{opts.get('id')}" From 7f7a16d7eaa875f105c491a81c1b5cefba05f0af Mon Sep 17 00:00:00 2001 From: yogeshwaran-c Date: Wed, 29 Apr 2026 14:34:09 +0530 Subject: [PATCH 2/2] fix(python): refine utils type hints per review (Optional handling, future type) --- python/bullmq/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/bullmq/utils.py b/python/bullmq/utils.py index 2a281a9dd46..a0a039b22ab 100644 --- a/python/bullmq/utils.py +++ b/python/bullmq/utils.py @@ -1,16 +1,18 @@ import asyncio import json import traceback -from typing import Any, Callable, Optional +from typing import Any, Callable import semver -def isRedisVersionLowerThan(current_version: str, minimum_version: str) -> bool: +def isRedisVersionLowerThan(current_version: str | None, minimum_version: str) -> bool: + if current_version is None: + return False return semver.Version.parse(current_version).compare(minimum_version) == -1 -def extract_result(job_task: asyncio.Task, emit_callback: Callable[[str, Any], None]) -> Any: +def extract_result(job_task: asyncio.Future[Any], emit_callback: Callable[[str, Any], None]) -> Any: try: return job_task.result() except Exception as e: @@ -20,9 +22,10 @@ def extract_result(job_task: asyncio.Task, emit_callback: Callable[[str, Any], N traceback.print_exc() emit_callback("error", e) -def get_parent_key(opts: dict[str, str]) -> Optional[str]: +def get_parent_key(opts: dict[str, str] | None) -> str | None: if opts: return f"{opts.get('queue')}:{opts.get('id')}" + return None def parse_json_string_values(input_dict: dict[str, str]) -> dict[str, dict]: return {key: json.loads(value) for key, value in input_dict.items()}