Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions taskiq_flow/scheduling/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import logging
from datetime import datetime
from typing import Any, cast
from typing import Any, Optional, cast

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.

medium

By adding from __future__ import annotations at the very top of this file, we can avoid importing Optional entirely and keep the imports clean.

Suggested change
from typing import Any, Optional, cast
from typing import Any, cast


from taskiq import AsyncBroker

Expand Down Expand Up @@ -381,7 +381,7 @@ class PipelineScheduler:
def __init__(
self,
broker: AsyncBroker,
scheduler: AsyncIOScheduler | None = None,
scheduler: Optional[AsyncIOScheduler] = None,

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.

medium

Instead of switching to Optional[AsyncIOScheduler] and introducing inconsistency with the rest of the codebase (which consistently uses the | None union syntax, such as job_store_url: str | None on the next line), we can resolve the runtime TypeError (which occurs when apscheduler is not installed and AsyncIOScheduler is None) by adding from __future__ import annotations at the top of the file.

This postpones the evaluation of annotations, allowing us to safely use AsyncIOScheduler | None without runtime crashes.

Suggested change
scheduler: Optional[AsyncIOScheduler] = None,
scheduler: AsyncIOScheduler | None = None,

job_store_url: str | None = None,
) -> None:
if AsyncIOScheduler is None:
Expand Down
Loading