sbdchd / django-types

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

Typing for `as_manager` #220

Open max-muoto opened 8 months ago

max-muoto commented 8 months ago

While I get this isn't technically accurate:

class ModelAQuerySet(models.QuerySet["ModelA"]):
   def custom_method(self) -> Self:
      ...

class ModelA(models.Model):
   objects: ModelAQuerySet = ModelAQuerySet.as_manager() # Pyright: Manager cannot be assigned to queryset

Isn't it for all intensive purposes the closest to the most accurate type? While I understand Django is dynamically creating a new type, not typing this as the queryset will lose us all of the custom methods we added. I think django-types solves this problem for mypy with this plugin, but if you're using Pyright this is probably what you would want to do.