-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add stub files for pymongo
and bson
#408
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
Conversation
Awesome! It looks like this fixes a lot of mypy errors:
The remaining issues I see are:
Some of these issues can be fixed by adding a Can you also include the new files in the pypi package so we can become PEP-561 compatible? I think we just need to add this to setup.py:
I think we can at least test with mypy. I'll open a new issue for this because I don't want to hold up the PR but for now can we try to get mypy to pass locally when run on the |
45bc5fd
to
a7e297f
Compare
Thanks for the reminder for the package_data, I did want to do that. About the issues that you've uncovered: running I've added a lot of the 3.6 and 3.7 new stuff (array_filters, session, watch). However I do not have a good way of checking what's missing yet. So we might play catchup with some of the library's users that are using both typing and newest features. |
Just a quick update to anyone watching this PR, this is on our list to tackle soon. We haven't forgotten and know a lot of users are interested in it. |
@behackett What about now, is it still not forgotten? :) I'm working on a new project using PyMongo and the lack of type hints or stub files is pretty annoying. |
It's at the top of our list post MongoDB 4.4 which is rapidly approaching. |
what's the status of this? |
I created a |
I'd like to provide an update as this project was just completed. While working on this project our team realized that we would be more comfortable following a more conservative approach to adding type hints. Instead of including type annotations or stub files directly in pymongo we decided to ship stub files as a separate package: pymongo-stubs. pymongo-stubs' source code is hosted on GitHub (mongodb-labs/pymongo-stubs). The initial release is compatible with PyMongo >=3.11,<4.0 and Python >=3.6. @pcorpet you'll notice that you are already a contributor because I merged these changes as a starting point for the new project. Thank you for your contribution! Our longer term plan is to get feedback on the type hints and later (in PyMongo 4.0) incorporate them directly into the codebase as inline type annotations (in PYTHON-2432). For now you are welcome to try out the stubs like this:
Or simply install pymongo-stubs to get a better IDE experience: |
This is a follow up to #346 that was closed inadvertently.
It implements what was decided in this JIRA ticket: add type annotations in stubs according to PEP 484.
I took the work of @GrierPhillips and tried to answer some of the comments on the previous PR:
bson
package as well, aspymongo
references it sometimesI did not find a way to automatically test the stubs against real code as this is ongoing work by the
mypy
team. However I copied the.pyi
files intypeshed
and ran the tests there that helped me find and fix many issues.Also I did not update
pymongo
with updates from version after 3.5 (Phillips' work).This change is