Im currently working through the fastAPI tutorial, and my environment is setup with black, flake8, bandit and mypy. Everything in the tutorial is working fine, but I keep having to # type: ignore things to make mypy cooperate.
class Item(BaseModel):
name: str
description: str = None
price: float
tax: float = None
@app.post("/items/")
async def create_items(item: Item) -> Item:
return item
Mypy then errors:
❯ mypy main.py [14:34:08]
main.py:9: error: Incompatible types in assignment (expression has type "None", variable has type "str")
main.py:11: error: Incompatible types in assignment (expression has type "None", variable has type "float")
I could # type: ignore, but then I lose the type hints and validation in my editor. Am I missing something obvious, or should I just disable mypy for FastAPI projects?