Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Generics on document type #11

@Doekeb

Description

@Doekeb

Thanks again for the stubs!

There is a slight fundamental difference between typing in pymongo and this package. Namely, many pymongo classes are generic on the document type. See pymongo.MongoClient as the main example. The client is created with the document_class keyword argument which defaults to dict. This allows methods like Collection.find_one to be very specific about their return type (e.g. if the collection belongs to a client where the document class is dict, then the return type of Collection.find_one is dict[str, Any]).

Currently, this package is set up to always return _Document = typing.Mapping[str, typing.Any] (https://github.com/L0RD-ZER0/Motor-Types/blob/8ffaa4fb9c0e9e93ef0425ea761b47d0502b1d87/motor-stubs/core.pyi#L31C1-L31C44). While this behavior is not incorrect per se, it does present a major development experience difference between the two packages (and after all, motor is built to very closely mirror pymongo).

For what it's worth, I never use anything other than dict as the document class in either package and I find the constant need for defining everything to be generic on the document class to be quite cumbersome. Nevertheless, I thought I would create this issue to hopefully spark a discussion around the topic 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions