Skip to content

add __class_getitem__ to QuerySet and Manager #11849

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django/db/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ def __hash__(self):


class Manager(BaseManager.from_queryset(QuerySet)):
pass
# for static type-checking only, no effects on runtime
def __class_getitem__(cls, *args, **kwargs):
return cls



class ManagerDescriptor:
Expand Down
4 changes: 4 additions & 0 deletions django/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def __init__(self, model=None, query=None, using=None, hints=None):
self._iterable_class = ModelIterable
self._fields = None

# for static type-checking only, no effects on runtime
def __class_getitem__(cls, *args, **kwargs):
return cls

def as_manager(cls):
# Address the circular dependency between `Queryset` and `Manager`.
from django.db.models.manager import Manager
Expand Down