BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.94k stars 203 forks source link

[BUG] `Document` constructor fails type check for instantiation with Mypy in `strict` mode #812

Closed johnthagen closed 7 months ago

johnthagen commented 7 months ago

Describe the bug

Beanie is missing complete type annotations on some objects, such as Document, which cause Mypy to fail when used.

To Reproduce

The following code:

from beanie import Document

d = Document()

Throws a type check error when run with Mypy:

$ mypy main.py
main.py:3: error: Call to untyped function "Document" in typed context  [no-untyped-call]
Found 1 error in 1 file (checked 1 source file)

With the following Mypy configuration:

[tool.mypy]
strict = true

plugins = [
    "pydantic.mypy",
]

This config can be further simplified to

[tool.mypy]
disallow_untyped_calls = true

plugins = [
    "pydantic.mypy",
]

This seems to be because this line, the constructor is not fully typed, it is missing -> None:

https://github.com/roman-right/beanie/blob/5f03c6f6312fd0232505cc9bebf8ac1b22ca95ac/beanie/odm/documents.py#L189

Expected behavior

No Mypy type check errors when using Beanie, even with in strict mode.

Additional context

Reproduced on:

Somewhat related to