Repository navigation
fix(job): use Optional for parameters defaulting to None [python] - #4908
Conversation
Parameters annotated as `str`/`dict`/`Redis` but defaulting to `None` are implicit Optional, which PEP 484 and the current typing spec prohibit. Type checkers analysing bullmq as an external package pick `job_id: str`, hiding that `None` is accepted. Annotate them as Optional: Job.job_id and Job.token, the upsertJobScheduler job_name/opts/producer_id arguments, the producer_id arguments of Scripts.addJobScheduler and Scripts.updateJobSchedulerNextMillis, and Scripts.extendLock's client. Fixes taskforcesh#4905 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The annotations accurately reflect existing nullable behavior, and an AST check found no remaining implicit-Optional parameters.
0 open findings
What changed in this PR
Corrects Python type annotations for parameters and fields that accept None.
Changes:
- Marks nullable job IDs, tokens, scheduler options, producer IDs, and Redis clients as
Optional. - Adds required
Optionalimports without changing runtime behavior.
| File | Description |
|---|---|
python/bullmq/job.py |
Corrects nullable job ID and token types. |
python/bullmq/queue.py |
Corrects scheduler API parameter types. |
python/bullmq/scripts.py |
Corrects nullable script parameter types. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
🎉 This PR is included in version 3.3.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 6.3.13 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.3.6 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.2.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Port Impact Checklist
Why
Parameters annotated
str(ordict/Redis) but defaulting toNoneare implicit Optional, which PEP 484 and the current typing spec prohibit. When bullmq is used as an external package, type checkers therefore pickjob_id: strand hide thatNoneis accepted, soJob(queue, name, data, job_id=None)is reported as an error andJob.idis typedstr.Fixes #4905
How
Annotated these as
Optional[...], matching the style already used in the package (e.g.Optional[str] = Noneinredis_connection.py):Job.__init__(job_id)andJob.tokenQueue.upsertJobScheduler(job_name, opts, producer_id)Scripts.addJobSchedulerandScripts.updateJobSchedulerNextMillis(producer_id)Scripts.extendLock(client)An AST scan of
python/bullmqfinds no remaining implicit-Optional parameters.Additional Notes (Optional)
Optionalimport.Job(..., job_id=None)andupsertJobScheduler(job_name=None, opts=None, producer_id=None)produced 4 errors andJob.idwasstr; after, 0 errors andJob.idisstr | None.Job.idis now honestlyOptional[str], somypy --no-implicit-optionalreports a few new "str | Nonepassed wherestrexpected" errors whereidis forwarded (e.g.scripts.toKey,moveToFinished,LockManager.track_job). These were latent before; CI installs mypy but does not run it. Happy to follow up with narrowing there if wanted.E9,F63,F7,F82) passes and the changed files compile.🤖 Generated with Claude Code