You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I.e. it uses List for the document_models argument.
To Reproduce
importasynciofrommotorimportmotor_asynciofrombeanieimportDocument, init_beanie### these will come from other modulesclassSample(Document):
name: strclassAnother(Document):
greeting: strsome_models= [Sample]
more_models= [Another]
###DOCUMENT_MODELS= [
*some_models,
*more_models,
]
asyncdefmain() ->None:
client=motor_asyncio.AsyncIOMotorClient('mongodb://mongo')
database=client['mydatabase']
awaitinit_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.
Additional context
none
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: