beanie icon indicating copy to clipboard operation
beanie copied to clipboard

[BUG] mypy strict no-untyped-call

Open aaronted009 opened this issue 1 year ago • 3 comments

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.

aaronted009 avatar Jan 23 '24 11:01 aaronted009

Thank you for the catch! I'll add this case to the typing tests suite

roman-right avatar Feb 08 '24 19:02 roman-right

Can I submit a PR for this

aaronted009 avatar Feb 13 '24 16:02 aaronted009

I would also like to see this implemented. It bugs me to have to use # type: ignore every time i use a operator

joaoheusi avatar Mar 13 '24 22:03 joaoheusi