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

MOTOR-1285 Add generics to type stubs #272

Merged
merged 41 commits into from Apr 1, 2024
Merged

Conversation

Doekeb
Copy link
Contributor

@Doekeb Doekeb commented Mar 23, 2024

This PR adds generics to type stubs to match pymongo. For example, MongoClient is generic on its _DocumentType. This PR makes AgnosticClient, AsyncIOMotorClient, and MotorClient also generic on the same _DocumentType (as well as all the other classes where the corresponding pymongo class is generic, including Database, Collection, ChangeStream, and the various Cursors).

doeke added 30 commits March 22, 2024 22:43
@blink1073
Copy link
Member

Hi @Doekeb, thanks for adding this! Out of curiosity, were you wanting to use this feature yourself, or did you want to add this for completeness with the PyMongo API?

Also, can you please add a test similar to this one in PyMongo?

Of note, we are planning to release 3.4 either tomorrow or the next day.

@blink1073 blink1073 changed the title Add generics to type stubs MOTOR-1285 Add generics to type stubs Mar 25, 2024
@Doekeb
Copy link
Contributor Author

Doekeb commented Mar 25, 2024

Thanks for taking a look! I'm definitely interested in using it myself, but I do think it's quite nice to have parity with PyMongo. My use case is a data access API layer where both PyMongo and Motor are used (PyMongo for everyday use, e.g. fetch some data in a notebook and put it into a pandas DataFrame, and Motor mainly for listening to a change stream). It's nice to be able to have parallel definitions everywhere. Also, making everything generic on the document type allows one to be more sure about the nature of returned documents (e.g. you can do more things with a dict[str, Any] or a RawBSONDocument than you can with a general Mapping[str, Any]).

I probably won't have a chance to implement those test for at least the next couple of days, but I'm happy to do so when I get a chance!

@blink1073
Copy link
Member

Okay, sounds good! We'll save it for the 3.5 release then, which will most likely coincide with PyMongo 4.7.

@Doekeb
Copy link
Contributor Author

Doekeb commented Mar 31, 2024

Just added those tests, ready for another look!

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much!

@blink1073 blink1073 merged commit 96aeb40 into mongodb:master Apr 1, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants