You can get a TypeError: 'type' object is not subscriptable
when you will try to use QuerySet[MyModel], Manager[MyModel] or some other Django-based Generic types.
This happens because these Django classes do not support __class_getitem__ magic method in runtime.
You can go with django_stubs_ext helper, that patches all the types we use as Generic in django.
Install it:
pip install django-stubs-ext # as a production dependency
You can add extra types to patch with django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])
You can use strings instead: 'QuerySet[MyModel]' and 'Manager[MyModel]', this way it will work as a type for type-checking and as a regular str in runtime.
As a newcomer to types in Python, I find this whole section confusing. But the bug I want to report is that the link to django_stubs_ext is broken. The directory django_stubs_ext doesn't seem to exist any more.
In the README.md file, there is this section:
As a newcomer to types in Python, I find this whole section confusing. But the bug I want to report is that the link to
django_stubs_ext
is broken. The directorydjango_stubs_ext
doesn't seem to exist any more.