sbdchd / django-types

:doughnut: Type stubs for Django
MIT License
186 stars 62 forks source link

Link to django_stubs_ext is broken #216

Open Flimm opened 8 months ago

Flimm commented 8 months ago

In the README.md file, there is this section:

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.

  1. 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

    And then place in your top-level settings:

    import django_stubs_ext
    
    django_stubs_ext.monkeypatch()

    You can add extra types to patch with django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])

  2. 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.