Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mypy strict no-untyped-call #836

Open
aaronted009 opened this issue Jan 23, 2024 · 3 comments · May be fixed by #925
Open

[BUG] mypy strict no-untyped-call #836

aaronted009 opened this issue Jan 23, 2024 · 3 comments · May be fixed by #925

Comments

@aaronted009
Copy link

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.

@roman-right
Copy link
Member

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

@aaronted009
Copy link
Author

Can I submit a PR for this

@joaoheusi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants