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.
- Could you show me a concrete type-checking issue that this change resolves?
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.
- Is this only useful together with the
django-restframeworkstubs
package?
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 doesn't appear to have adopted
__class_getitem__
for it's generic views or for QuerySets and Managers. I'd normally expect us to follow Django's lead on this kind of design issue. Is there any context we can see there involving similar design discussions against the Django project?
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.