Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripts): Type Hinting wit Union type instead of | operator #1780

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/bullmq/job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from redis import Redis
from typing import List, Any, TypedDict, Literal
from typing import List, Any, TypedDict, Optional

import json
import time
Expand Down Expand Up @@ -112,7 +112,7 @@ def __init__(self, client: Redis, name: str, data: Any, opts: JobOptions = {}):
self.stacktrace: List[str] = []


def fromJSON(client: Redis, rawData: dict, jobId: str | None = None):
def fromJSON(client: Redis, rawData: dict, jobId: Optional[str] = None):
"""
Instantiates a Job from a JobJsonRaw object (coming from a deserialized JSON object)

Expand Down
6 changes: 3 additions & 3 deletions python/bullmq/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def moveToCompleted(self, job: Job, val: Any, removeOnComplete, token: str, opts
def moveToFailed(self, job: Job, failedReason: str, removeOnFailed, token: str, opts: dict, fetchNext=True):
return self.moveToFinished(job, failedReason, "failedReason", removeOnFailed, "failed", token, opts, fetchNext)

async def moveToFinished(self, job: Job, val: Any, propVal: str, shouldRemove, target, token: str, opts: dict, fetchNext=True) -> list[Any] | None:
async def moveToFinished(self, job: Job, val: Any, propVal: str, shouldRemove, target, token: str, opts: dict, fetchNext=True) -> Union[list[Any],None]:
timestamp = round(time.time() * 1000)
metricsKey = self.toKey('metrics:' + target)

Expand All @@ -148,7 +148,7 @@ async def moveToFinished(self, job: Job, val: Any, propVal: str, shouldRemove, t
keys.append(self.keys['meta'])
keys.append(metricsKey)

def getKeepJobs(shouldRemove: bool | dict | int | None):
def getKeepJobs(shouldRemove: Union[bool,dict,int,None]):
if shouldRemove == True:
return {"count": 0}

Expand Down Expand Up @@ -228,7 +228,7 @@ def finishedErrors(code: int, jobId: str, command: str, state: str) -> TypeError
return TypeError(f"Unknown code {str(code)} error for {jobId}.{command}")


def raw2NextJobData(raw: list[Any]) -> list[Any] | None:
def raw2NextJobData(raw: list[Any]) -> Union[list[Any],None]:
if raw:
# TODO: return all the raw datas (up to 4)
if raw[0]:
Expand Down