I.e. it uses List for the document_models argument.
To Reproduce
import asyncio
from motor import motor_asyncio
from beanie import Document, init_beanie
### these will come from other modules
class Sample(Document):
name: str
class Another(Document):
greeting: str
some_models = [Sample]
more_models = [Another]
###
DOCUMENT_MODELS = [
*some_models,
*more_models,
]
async def main() -> None:
client = motor_asyncio.AsyncIOMotorClient('mongodb://mongo')
database = client['mydatabase']
await init_beanie(database=database, document_models=DOCUMENT_MODELS)
if __name__ == '__main__':
asyncio.run(main())
Expected behavior
Code type checks using mypy
Actual behaviour
error: Argument "document_models" to "init_beanie" has incompatible type "list[type[Document]]"; expected "list[type[Document] | type[View] | str] | None" [arg-type]
note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
note: Consider using "Sequence" instead, which is covariant
Note that DOCUMENT_MODELS is generally compatible with with the expectation, but using List and Union here appears to result in this error. IMHO, this can be fixed by using Sequence instead, since this is an argument.
I'd be glad to provide a PR if this would fix the issue.
Describe the bug The current annotation of
init_beanie()
is:I.e. it uses
List
for thedocument_models
argument.To Reproduce
Expected behavior Code type checks using
mypy
Actual behaviour
Note that
DOCUMENT_MODELS
is generally compatible with with the expectation, but usingList
andUnion
here appears to result in this error. IMHO, this can be fixed by usingSequence
instead, since this is an argument.I'd be glad to provide a PR if this would fix the issue.
Additional context none