Technical Board statement on type hints for Django
Sorry for the late answer, I didn't have time to read this mailing list for the last month :-( Here's my position on the matter.
Adding type annotations only makes sense if a type checker checks them. Otherwise, they're unlikely to be correct and usable, so it would be counterproductive to add them. Unfortunately, I don't think we have a good enough type checker yet.
I'm having a rough experience maintaining type checking with mypy in websockets <
https://github.com/aaugustin/websockets>, a library that is very much smaller and simpler than Django. (Some problems are related to async, which isn't a concern for Django, but that doesn't explain everything.)
* Besides adding the type annotations, type checking required many other code changes. Importing types in modules that need them created circular dependencies. Fixing these import loops required moving imports to the bottom (ugh), splitting code in small modules (meh), or always importing modules rather than objects inside modules (perhaps a good practice, but changing this throughout a project creates a lot of noise). Also, import loops tend to reappear when implementing new features or refactoring.
* It's an uphill struggle to keep up with subtle changes of behavior in mypy — which is still 0.x software. I also encountered regressions that required pinning to an old version. Supporting more than one mypy version seems out of reach. I'm very pessimistic about supporting more than one type checker.
*
I don't remember mypy catching interesting bugs. I'm keeping it only because I'm failing to deal with the sunk cost logical fallacy :-( Overall, adding type annotation to websockets has decreased my ability and willingness to maintain it. I believe it increased the barrier to entry for other contributors as well.
So, I think the ecosystem needs to stabilize a lot before Django can adopt static typing, even just as a best practice for new code. Comments like this one <
https://github.com/django/deps/pull/65/files#r333706194> make me uncomfortable about living that close to the edge.
Also, given that static typing was bolted on Python very late in its history and that there's a strong tradition of relying on duck typing, I'm not yet convinced static typing will ever be widely accepted as a best practice.