From 9bce9859bf61aeeb0e0bbb46efd570dcca00b36d Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Wed, 4 Oct 2023 16:18:47 -0400 Subject: [PATCH] Annotate Field.default_error_messages as a ClassVar (#464) This clarifies that this field is set on the class itself, not on instances. --- rest_framework-stubs/fields.pyi | 4 ++-- rest_framework-stubs/serializers.pyi | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rest_framework-stubs/fields.pyi b/rest_framework-stubs/fields.pyi index e99e7d36c..f46c8a787 100644 --- a/rest_framework-stubs/fields.pyi +++ b/rest_framework-stubs/fields.pyi @@ -5,7 +5,7 @@ from decimal import Decimal from enum import Enum from json import JSONDecoder, JSONEncoder from re import Pattern -from typing import Any, Final, Generic, NoReturn, Protocol, TypeVar +from typing import Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar from django.core.files.base import File from django.db import models @@ -72,7 +72,7 @@ class Field(Generic[_VT, _DT, _RP, _IN]): allow_null: bool default: _VT | None default_empty_html: Any - default_error_messages: dict[str, StrOrPromise] + default_error_messages: ClassVar[dict[str, StrOrPromise]] default_validators: list[Validator[_VT]] error_messages: dict[str, StrOrPromise] field_name: str | None diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index 4676e63cc..e83845625 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence -from typing import Any, Generic, Literal, NoReturn, TypeVar +from typing import Any, ClassVar, Generic, Literal, NoReturn, TypeVar from django.db import models from django.db.models import Manager, Model, QuerySet @@ -125,7 +125,7 @@ class Serializer( metaclass=SerializerMetaclass, ): _declared_fields: dict[str, Field] - default_error_messages: dict[str, StrOrPromise] + default_error_messages: ClassVar[dict[str, StrOrPromise]] def get_initial(self) -> Any: ... @cached_property def fields(self) -> BindingDict: ... @@ -148,7 +148,7 @@ class ListSerializer( ): child: Field | BaseSerializer | None many: bool - default_error_messages: dict[str, StrOrPromise] + default_error_messages: ClassVar[dict[str, StrOrPromise]] allow_empty: bool | None def __init__( self,