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

Typing support #2777

Open
last-partizan opened this issue Nov 4, 2023 · 2 comments
Open

Typing support #2777

last-partizan opened this issue Nov 4, 2023 · 2 comments

Comments

@last-partizan
Copy link
Contributor

Hi folks

Are you interested in adding types to your project?

There is https://github.com/sbdchd/mongo-types project, but it's incomplete and outdated. But types can be integrated back into the original project.

If you're interested, i can try making a PR.

@bagerard
Copy link
Collaborator

This is a great idea but it all depends how much it will clutter this codebase. Although MongoEngine is way less complex and popular, it is worth mentioning this post from django on the same topic django/deps#65

I recently started testing mongo-types and fixed a bunch of issues, of course the dynamic nature of Documents, some Fields and Querysets makes typing quite tricky to get right, you may want to check it out here https://github.com/bagerard/mongo-types. I also see that the original project received some commits recently.

Alternative could be to get mongo-types under the MongoEngine umbrella, but as a separate library

@last-partizan
Copy link
Contributor Author

last-partizan commented Jun 17, 2024

I started working on this, and it was going fine until i got to fields.

To account for required parameter we need to do overloads, and writing so much overloads is not fun. django-stubs has mypy plugin for this, and in theory we can also make a plugin. But it will work only for mypy obviously.

But, what if mypy plugin was able to export it's generated types into pyi, for other type checkers to consume? I created an issue for mypy, and hoping for the best: python/mypy#17315

In the meantime, i'm thinking about writing some sort of script that will generate all those overrides, but for now it's only cool idea in my head.

https://github.com/last-partizan/mongoengine/tree/merge-stubs

PR: #2822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants