Hi all!
Only me here, just talking about how Django doesn’t support static analysis very well and that it doesn’t have many type hints. But, don’t worry, I’m not proposing that we add any! Pitchforks down.
This thread stems from a discussion with several community members in Athens, where I was arguing for the above, and eventually arrived at the conclusion that the actual problem I want to solve is not:
Django does not have any type hints
But rather it is:
Django does not interact well with typed code which is being statically analysed
And further to the above, not only does it obviously not interact well with typed code due to the lack of type hints, but critically: the developer experience of getting it to interact well is very poor and opaque.
I know how to make Django act like it is typed. And I am sure many here do also, but I do equally remember the first time I attempted this, and frankly, it wasn’t very pleasant, easy, or convenient to figure it all out, including ‘edge cases’ like custom Model fields, chained QuerySets, and custom model managers and custom QuerySets. And that was when I was approaching the problem as someone who is very confident with Python, and very familiar with Django.
A huge portion of Python users want to use type hints, or need to use type hints. It makes sense to me that we should support those people in doing so, and a very reasonable, low cost, low risk method of achieving that goal would be to produce a page, or section, of the documentation that covers the methods available for use:
django-stubsmypywith thedjango-stubspluginpyrightPyCharmdjango-mantlety- in the future
And provides an introduction to these things that is either:
- Reasonable enough that it encourages the user that Django can meet their needs in terms of integrating with a typed Python codebase
- Sufficiently explains why this tool is not appropriate for usage with Django, such as in the case of
pyrightand lack ofQuerySettype inference.
Personally, I also think that it would be polite and wise to provide some sort of explanation (at a very high level) as to why Django is not typed, and why Django cannot easily be typed (at least, for a lot of it, anyway).
Obviously mentioning third party packages is an ‘approved’ thing to do now (although I’m unclear who approves these mentions), so it seems very reasonable that we should support users who want to statically type their code by telling them what packages are likely to work best, where to find their documentation, and why we haven’t just put it in the core yet.
I can draft this page if people think it is a good idea. Perhaps I would start as a blog post and get feedback and adapt.
If someone could clarify my query about approval of mentioning third party packages in the documentation also, I would appreciate it!
Andrew ![]()