Skip to content

feat(flow-producer): add return type hints to methods [python] - #4088

Open
yogeshwaran-c wants to merge 3 commits into
taskforcesh:masterfrom
yogeshwaran-c:feat/python-flow-producer-type-hints
Open

feat(flow-producer): add return type hints to methods [python]#4088
yogeshwaran-c wants to merge 3 commits into
taskforcesh:masterfrom
yogeshwaran-c:feat/python-flow-producer-type-hints

Conversation

@yogeshwaran-c

Copy link
Copy Markdown
Contributor

Summary

Adds missing parameter and return type hints to the Python FlowProducer methods in python/bullmq/flow_producer.py to improve type clarity and IDE support.

Methods updated

  • queueFromNode — typed node: dict, queue_keys: QueueKeys, return -> MinimalQueue
  • addChildren — typed nodes: list[dict], parent: dict, queues_opts: Optional[dict], pipe: Any, return -> list[dict]
  • addNodes — typed pipe: Any, return -> list[dict]
  • addNode — typed queues_opts: Optional[dict] (was dict, but None is passed from addNodes), pipe: Any, return -> dict
  • add — return -> dict
  • addBulk — return -> list[dict]

Also imports Any and Optional from typing.

Return types are derived directly from the actual return values observed in the code (e.g. addNode returns {"job": job, "children": children} or {"job": job}). No runtime behavior changes.

Test plan

  • Python syntax validates (verified locally with ast.parse)
  • Existing Python tests continue to pass

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the Python BullMQ API ergonomics by adding missing parameter/return type hints to FlowProducer methods, improving IDE autocomplete and static analysis without changing runtime behavior.

Changes:

  • Add Any/Optional imports and annotate pipe and queues_opts where None is actually passed.
  • Add return type hints for queueFromNode, addChildren, addNodes, addNode, add, and addBulk.
  • Tighten parameter annotations for queueFromNode to use QueueKeys and return MinimalQueue.
Comments suppressed due to low confidence (1)

python/bullmq/flow_producer.py:137

  • With the new -> list[dict] return annotation, initializing result = None and later returning result will cause stricter type checkers (e.g., mypy) to infer result as Optional[list[dict]] and flag the return as incompatible. Prefer returning job_trees directly (or explicitly type result as list[dict]).
        result = None
        async with self.redisConnection.conn.pipeline(transaction=True) as pipe:
            job_trees = await self.addNodes(flows, pipe)
            await pipe.execute()
            result = job_trees

        return result

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/bullmq/flow_producer.py Outdated
Comment on lines 119 to 120
async def add(self, flow: dict, opts: dict = {}) -> dict:
parent_opts = flow.get("opts", {}).get("parent", None)

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts: dict = {} uses a mutable default argument. Even if currently treated as read-only, this can lead to shared state across calls and is discouraged. Prefer opts: Optional[dict] = None (or similar) and initialize an empty dict inside the method.

Copilot uses AI. Check for mistakes.
Comment thread python/bullmq/flow_producer.py Outdated
Comment on lines 122 to 128
@@ -127,7 +127,7 @@ async def add(self, flow: dict, opts: dict = {}):

return result

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new -> dict return annotation, initializing result = None and later returning result will cause stricter type checkers (e.g., mypy) to infer result as Optional[dict] and flag the return as incompatible. Prefer returning jobs_tree directly (or explicitly type result as dict).

Copilot uses AI. Check for mistakes.
@roggervalf roggervalf changed the title feat(python): add return type hints to FlowProducer methods feat(flow-producer): add return type hints to methods [python] Apr 23, 2026
…ift [python]

- Replace 'opts: dict = {}' with 'opts: dict | None = None' (PEP 604) to avoid mutable default

- Tighten dict-returning methods so the return value is never inferred as Optional[dict]
@yogeshwaran-c

Copy link
Copy Markdown
Contributor Author

Addressed Copilot review feedback in 12a0b11:

  • Mutable defaults: Replaced opts: dict = {} (and redisOpts: Union[dict, str] = {}) with PEP 604 X | None = None style in MinimalQueue.__init__ and FlowProducer.__init__. Each method now initializes the empty dict locally (opts = opts or {}).
  • Optional return drift: FlowProducer.addBulk no longer threads result = None through the function — it now returns job_trees directly inside the async with block, matching the -> list[dict] annotation. Also brought add() to the same PEP 604 style (opts: dict | None = None) for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants