|
There is a lot more than that. Reverse FKs, chained relations (foo__foofk__barfk__in), complexity regarding Django's several understandings of "abstract"/interfaces/protocols (abstract models, form classes that implicitly can or must provide methods with specific names/signatures depending on what fields are on the form, etc.), runtime-generated model classes (how and where to check in or tell the typechecker about those stubs?), lazy objects that change type (gaining and removing/changing behavior) at runtime based on things that are pretty hard for a type checker to notice, like random field access/indexing, and so on. And that's just the core Django dynamism; the stuff that needs to work really well. Not even getting into stuff that would be nice, like custom managers providing methods to model instances, Q/F type helpers, any sort of typing help with templates (even just "can this method be called with the signature this template wants"), complex model introspection typing, something cleaner than pydantic/manual TypedDicts for form data at the ser/de boundary, and so on. Even that bare minimum requires some pretty difficult features, type-checker wise: extremely distant dependent types ("if field X exists, method Y should take kwargs X__in and so on" as in your example, as well as "if field X exists, method get_X must be declared on class Y with signature Z", and "if field X exists, then a very distant method in a model manager needs to be documented to return type Y if values_list=True"), very robust support for runtime-created signatures that in a lot of Django systems cannot be generated and checked in (e.g. database-derived models or JSON-backed fields outside of Postgres), extremely complex dependent typing in classes whose generic bounds are determined pretty late/at mixin time (but which may also conceptually be mixins that can only be used in a very few appropriate cases), and more. Like, just think about model field names in manager method arguments--a tiny fraction of the problem. All the different chained/related kwargs would have to be computed and typed, as well as their disjoint: if I rename field "foo" to "bar", and forget to update some caller that does "m.objects.filter(thing__thing2_fk__foo__in=[1,2])", it'd be great if the type checker could help me catch that. But even if it can't, does that mean that "objects.filter" has all-optional typed kwargs and also takes **kwargs as well, because the type coverage is gradual? As soon as that's allowed, a whole lot of useful typechecking abilities go out the window since misnamed keys can just fall into the wildcard. Solvable, sure, but a major pain in the ass to implement--especially given that Django is a fast-moving target adding/removing/changing functionality all the time. Again, that's just Django basics. Things that ordinary, bog-standard, not-using-advanced-functionality Django code needs all the time. If the typechecker mishandles one of those cases and makes life harder, people will abandon it. There's a very tricky line to walk here re: when to be strict and when to give up on typechecking entirely, but Django has a lot of places where the latter is necessary. |
However my point was: type checkers of today can’t even handle the far more simple desires that I have.
It seems they aren’t committed towards dynamism as a default.