s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.79k stars 161 forks source link

Taskiq Mypy validation error #192

Open RoyalGoose opened 9 months ago

RoyalGoose commented 9 months ago

After initializing blank project with Taskiq Mypy gives an validation error

Format with Black........................................................Passed
isort....................................................................Passed
Check with Flake8........................................................Passed
Validate types with MyPy.................................................Failed
- hook id: mypy
- exit code: 1
project_name\tkq.py:9: error: Incompatible types in assignment (expression has
type "InMemoryBroker", variable has type "ZeroMQBroker")  [assignment]
        broker = InMemoryBroker()
                 ^~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 44 source files)

Initial project_name/tkq.py

import taskiq_fastapi
from taskiq import InMemoryBroker, ZeroMQBroker

from project_name.settings import settings

broker = ZeroMQBroker()

if settings.environment.lower() == "pytest":
    broker = InMemoryBroker()

taskiq_fastapi.init(
    broker,
    "project_name.web.application:get_app",
)
s3rius commented 9 months ago

Guess we need explicitly set type broker: AsyncBroker = ... at the beginning.