beanie
beanie copied to clipboard
[BUG] mypy strict no-untyped-call
Describe the bug When using Beanie with mypy strict typing, some typing issues make it impossible to pass the linter validation.
To Reproduce Here is an example of code:
import asyncio
from typing import Optional
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseModel
from beanie import Document, init_beanie, operators
class Category(BaseModel):
name: str
description: str
class Product(Document):
name: str
description: Optional[str] = None
price: float
category: Category
async def example() -> None:
client = AsyncIOMotorClient("mongodb://user:pass@host:27017")
await init_beanie(database=client["beanie_test"], document_models=[Product])
chocolate = Category(
name="Chocolate",
description="A preparation of roasted and ground cacao seeds.",
)
tonybar = Product(name="Tony's", price=5.95, category=chocolate)
await tonybar.insert()
product = await Product.find_one(operators.LTE(Product.price, 10))
if __name__ == "__main__":
asyncio.run(example())
Here is the output.
$ > mypy --stritct _local/test_mypy_1.py
test_mypy_1.py:35: error: Call to untyped function "LTE" in typed context [no-untyped-call]
Expected behavior There should be no error
I believe this can be fixed by specifying the NoneType for the functions missing it.
If no objection, I can submit a Pull Request for the changes.
Thank you for the catch! I'll add this case to the typing tests suite
Can I submit a PR for this
I would also like to see this implemented. It bugs me to have to use # type: ignore
every time i use a operator