Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing for as_manager #220

Open
max-muoto opened this issue Jan 2, 2024 · 0 comments
Open

Typing for as_manager #220

max-muoto opened this issue Jan 2, 2024 · 0 comments

Comments

@max-muoto
Copy link

max-muoto commented Jan 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant