-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use plugin to support Django models #3539
Comments
This was originally discussed at #1240. |
@dmoisset You might be interested in this. |
Hi folks, there is some interest coming into helping out on Django stubs (we're organising over at https://gitter.im/mypy-django/Lobby if you would like to chat) although I am pretty confused as to what direction to kick off with. Some questions ...
Thanks! PS. @dmoisset, we're basing our initial investigation off your great start, please join the chat if you're around to hand out some advice, it would be much appreciated! |
Hi @lwm, Regardless of what solution is chosen, I strongly recommend, and hope we can all agree, that keeping the stubs and the plugin together will make everything simpler. Here are the two best options I see:
I recommend option 1, the stubs and plugin are put in a django-stubs package. #5358 will help make loading the plugin. While many people use Django, it would reduce the maintenance work by the mypy team and allow for faster iteration on the stubs. |
Thanks @ethanhs, happy to go with your recommended approach. I'm asking a heck of a lot of questions but I'll keep going - what is meant by 'a plugin for django'? I'm not quite sure what is the purpose of the plugin and why we need it. EDIT: I've added typeddjango/django-stubs#5 to track more specifics if needed. |
@lwm the idea is that Django models do some rather dynamic things that mypy does not, nor will not in the near future, support. Therefore, if there is a plugin for mypy which knows about how these models work, people can still get some type safety when using mypy in conjunction with Django. There is a plugin for attrs which lives in the mypy sources which you may be interested in. |
Thanks @ethanhs, I'll give that existing plugin a look over and see how I go 👍 |
Great, let me know (here or on Gitter) if you have questions. There is usually someone around who can answer your questions on the typing Gitter. |
Hi, I've been looking in to typing Django models myself, which would be a massive benefit for my client's project. The plugin approach seems the clear winner, and I would love to see that in mypy. But I understand its quite challenging and might take some time. In the meantime, I've been trying to put together another solution that might work for us (and other projects). It's just a days work, but I've fudged together a script which can import Django models, inspect them and output .pyi files. It's not quite finished, but in theory it should cover all the field attributes and the dynamic attributes Django adds. I was wondering if anyone has tried such an approach and if its worth persevering? Somewhat related is an issue I had with the inspect lib, which I use to extract method signatures from the models. The
Which mypy rejects, because of the use of parenthesis in |
@willmcgugan This is an interesting approach, somewhere in between Regarding your question, this is caused by the fact that all string literals that appear as type parameters are internally wrapped in a special class |
I think this can be closed, there is a Django plugin actively developed in a separate repo: https://github.com/mkurnikov/django-stubs. All further discussion about supporting various Django features could continue there. |
We'd also need stubs for Django. Django is very popular so having the plugin live in the mypy repo would be reasonable.
The text was updated successfully, but these errors were encountered: