Allow generic requests, responses, fields, views by jalaziz · Pull Request #8825 · encode/django-rest-framework (original) (raw)

By making these classes generic, type checkers can more easily do their job when working with DRF classes.

It doesn't solve a type-checking issue per se, it solves a problem that occurs when you try to monkey-patch type support. Will try to put up an example project to show the issue, but fundamentally the issue is, unlike Django, DRF eagerly loads settings on import which results in improper settings when trying to monkey patch classes too early.

Yes and no. Today, django-restframeworkstubs provides support for typing where DRF lacks typing support. There's nothing stopping another stubs implementation or for DRF to provide native typing support.

Django does support __class_getitem__ for QuerySets, Managers, and ForeignKey. It's true that support hasn't been added for generic views, but that's just a matter of someone contributing support, I believe.