-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Python Drivers
The types returned by client.get_database() and client[database] are identical. The type annotations are inconsistent: client.get_database() is annotated as Database where client[database] is annotated as AgnosticDatabase. Using get_database() will therefore produce incorrect warnings from mypy.
Instead it should also by annotated to return an AgnosticDatabase so that mypy produces correct results.
from motor.motor_asyncio import AsyncIOMotorClient MONGODB_URI="mongodb+srv://username:password@hostname/database?retryWrites=true&w=majority&appName=test" client = AsyncIOMotorClient(MONGODB_URI) db=client.get_database() # preferred way, allows to configure database name without extra code db=client["database"] # suboptimal way, requires extra code, produces correct type annotations
Motor version is 3.3.2.