Both ty and Pyre are in development, so maybe the answer is just "this works and they don't". But they do promise to work eventually, like end of year if I recall correctly. I don't know what makes Django special in this regard though - is it the ORM models that don't work well with the typing spec or..?
davidhalter|8 months ago
The ORM models do not work with typing at all, you basically have to make a lot of magic work if you want to support it in a type checker (especially if you want to work with reverse foreign keys). Generally type checkers do not just support the Django ORM. For Mypy there's a plugin that works pretty well, but uses runtime information, which further slows down Mypy.
zem|8 months ago
it's not just django btw, pretty much any metaprogramming library needs that sort of custom support, including dataclasses - take a look at any python type checker and you will find code specifically replicating what dataclasses does in terms of code generation. for pytype we actually put dataclass and namedtuple support alongside our other third-party plugins in the codebase.
ehutch79|8 months ago
The foreign key stuff and missing reverse relations in types a big issue, but there's other stuff like warning about class Meta: being incompatible because you're inheriting an abstract model.
I'm yet to find a good guide on how to handle typing a django project, even if only to get vscode to do autocomplete.
drcongo|8 months ago