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

[3.15] Add __class_getitem__ of classes #585

Merged
merged 7 commits into from
Apr 15, 2024
Merged
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
1 change: 1 addition & 0 deletions rest_framework-stubs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Field(Generic[_VT, _DT, _RP, _IN]):
validators: Sequence[Validator[_VT]] | None = ...,
allow_null: bool = ...,
) -> None: ...
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> type[Self]: ...
def bind(self, field_name: str, parent: BaseSerializer) -> None: ...
@property
def validators(self) -> list[Validator[_VT]]: ...
Expand Down
2 changes: 2 additions & 0 deletions rest_framework-stubs/generics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from rest_framework.pagination import BasePagination
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import BaseSerializer
from typing_extensions import Self

_MT_co = TypeVar("_MT_co", bound=Model, covariant=True)
_MT_inv = TypeVar("_MT_inv", bound=Model)
Expand Down Expand Up @@ -37,6 +38,7 @@ class GenericAPIView(views.APIView, UsesQuerySet[_MT_co]):
lookup_url_kwarg: str | None
filter_backends: Sequence[type[BaseFilterBackend | BaseFilterProtocol[_MT_co]]]
pagination_class: type[BasePagination] | None
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> type[Self]: ...
def get_object(self) -> _MT_co: ...
def get_serializer(self, *args: Any, **kwargs: Any) -> BaseSerializer[_MT_co]: ...
def get_serializer_class(self) -> type[BaseSerializer[_MT_co]]: ...
Expand Down
2 changes: 2 additions & 0 deletions rest_framework-stubs/request.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from rest_framework.negotiation import BaseContentNegotiation
from rest_framework.parsers import BaseParser
from rest_framework.versioning import BaseVersioning
from rest_framework.views import APIView
from typing_extensions import Self

def is_form_media_type(media_type: str) -> bool: ...

Expand Down Expand Up @@ -58,6 +59,7 @@ class Request(HttpRequest):
negotiator: BaseContentNegotiation | None = ...,
parser_context: dict[str, Any] | None = ...,
) -> None: ...
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> type[Self]: ...
@property
def content_type(self) -> str: ... # type: ignore[override]
@property
Expand Down
2 changes: 2 additions & 0 deletions rest_framework-stubs/response.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from django.test.utils import ContextList
from django.urls import ResolverMatch
from rest_framework.request import Request
from rest_framework.test import APIClient
from typing_extensions import Self

class Response(SimpleTemplateResponse):
data: Any
Expand All @@ -22,6 +23,7 @@ class Response(SimpleTemplateResponse):
exception: bool = ...,
content_type: str | None = ...,
) -> None: ...
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> type[Self]: ...
@property
def rendered_content(self) -> Any: ...
def render(self) -> Any: ...
Expand Down
5 changes: 0 additions & 5 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ rest_framework.views.AsView
rest_framework.views.GenericView

# Added in 3.15:
rest_framework.fields.Field.__class_getitem__
rest_framework.filters.search_smart_split
rest_framework.generics.GenericAPIView.__class_getitem__
rest_framework.request.Request.__class_getitem__
rest_framework.response.Response.__class_getitem__
rest_framework.serializers.Field.__class_getitem__
rest_framework.serializers.ListSerializer.run_child_validation
rest_framework.serializers.ModelSerializer.get_unique_together_constraints
rest_framework.templatetags.rest_framework.optional_logout
Expand Down