Conversation
Changes type annotations for the scheduler parameter from union syntax (`AsyncIOScheduler | None`) to the `Optional` generic type for consistency across the codebase. Also adds `Optional` to the typing imports.
There was a problem hiding this comment.
Code Review
This pull request modifies taskiq_flow/scheduling/scheduler.py to replace the union type hint AsyncIOScheduler | None with Optional[AsyncIOScheduler]. The reviewer suggests using from __future__ import annotations instead, which allows keeping the cleaner AsyncIOScheduler | None syntax, avoids runtime errors when apscheduler is not installed, and maintains consistency with the rest of the codebase.
| import logging | ||
| from datetime import datetime | ||
| from typing import Any, cast | ||
| from typing import Any, Optional, cast |
| self, | ||
| broker: AsyncBroker, | ||
| scheduler: AsyncIOScheduler | None = None, | ||
| scheduler: Optional[AsyncIOScheduler] = None, |
There was a problem hiding this comment.
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.
| scheduler: Optional[AsyncIOScheduler] = None, | |
| scheduler: AsyncIOScheduler | None = None, |
Changes type annotations for the scheduler parameter from union syntax (
AsyncIOScheduler | None) to theOptionalgeneric type for consistency across the codebase. Also addsOptionalto the typing imports.