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] Type error calling init_beanie() #670

Closed
markedwards opened this issue Aug 22, 2023 · 3 comments · Fixed by #784
Closed

[BUG] Type error calling init_beanie() #670

markedwards opened this issue Aug 22, 2023 · 3 comments · Fixed by #784

Comments

@markedwards
Copy link

Describe the bug
There is a type error calling init_beanie():

Argument "document_models" to "init_beanie" has incompatible type "list[type[Document]]"; expected "list[type[<nothing>] | type[View] | str] | None"  [arg-type]

To Reproduce

from beanie import Document, init_beanie
from motor.motor_asyncio import AsyncIOMotorClient


class MyModel(Document):
    foo: str


async def example() -> None:
    client = AsyncIOMotorClient("mongodb://user:pass@host:27017")
    await init_beanie(database=client.db_name, document_models=[MyModel])  # <- raises the type error

Expected behavior
No type error.

Additional context

@markedwards markedwards changed the title [BUG] [BUG] Type error calling init_beanie() Aug 22, 2023
@roman-right
Copy link
Member

Hi @markedwards ,
Could you please tell what are you using? MyPy or pyright, and respective version. Thank you

@markedwards
Copy link
Author

markedwards commented Sep 11, 2023

@roman-right -- mypy 1.5.1.

I believe you need to have strict=True set in order to reveal the error.

My guess is this can be resolved with this signature:

document_models: Optional[Sequence[Union[Type["DocType"], Type["View"], str]]]

or even simpler:

document_models: Optional[Sequence[Union[Type[Document], Type[View], str]]]

@cojua8
Copy link

cojua8 commented Oct 16, 2023

I think you are right, that change should be enough

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