Skip to content

Commit 9bce985

Browse files
authored
Annotate Field.default_error_messages as a ClassVar (#464)
This clarifies that this field is set on the class itself, not on instances.
1 parent b2e3b52 commit 9bce985

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: rest_framework-stubs/fields.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from decimal import Decimal
55
from enum import Enum
66
from json import JSONDecoder, JSONEncoder
77
from re import Pattern
8-
from typing import Any, Final, Generic, NoReturn, Protocol, TypeVar
8+
from typing import Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar
99

1010
from django.core.files.base import File
1111
from django.db import models
@@ -72,7 +72,7 @@ class Field(Generic[_VT, _DT, _RP, _IN]):
7272
allow_null: bool
7373
default: _VT | None
7474
default_empty_html: Any
75-
default_error_messages: dict[str, StrOrPromise]
75+
default_error_messages: ClassVar[dict[str, StrOrPromise]]
7676
default_validators: list[Validator[_VT]]
7777
error_messages: dict[str, StrOrPromise]
7878
field_name: str | None

Diff for: rest_framework-stubs/serializers.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
2-
from typing import Any, Generic, Literal, NoReturn, TypeVar
2+
from typing import Any, ClassVar, Generic, Literal, NoReturn, TypeVar
33

44
from django.db import models
55
from django.db.models import Manager, Model, QuerySet
@@ -125,7 +125,7 @@ class Serializer(
125125
metaclass=SerializerMetaclass,
126126
):
127127
_declared_fields: dict[str, Field]
128-
default_error_messages: dict[str, StrOrPromise]
128+
default_error_messages: ClassVar[dict[str, StrOrPromise]]
129129
def get_initial(self) -> Any: ...
130130
@cached_property
131131
def fields(self) -> BindingDict: ...
@@ -148,7 +148,7 @@ class ListSerializer(
148148
):
149149
child: Field | BaseSerializer | None
150150
many: bool
151-
default_error_messages: dict[str, StrOrPromise]
151+
default_error_messages: ClassVar[dict[str, StrOrPromise]]
152152
allow_empty: bool | None
153153
def __init__(
154154
self,

0 commit comments

Comments
 (0)