Skip to content

Commit

Permalink
Make error_messages and default_error_messages types stricter (#1592)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
intgr and pre-commit-ci[bot] authored Sep 2, 2023
1 parent 85e1f3f commit 3a1f139
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 75 deletions.
12 changes: 6 additions & 6 deletions django-stubs/contrib/auth/forms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models.fields import _ErrorMessagesT
from django.db.models.fields import _ErrorMessagesDict
from django.forms.fields import _ClassLevelWidgetT
from django.forms.widgets import Widget
from django.http.request import HttpRequest
Expand All @@ -28,7 +28,7 @@ class UsernameField(forms.CharField):
def widget_attrs(self, widget: Widget) -> dict[str, Any]: ...

class BaseUserCreationForm(forms.ModelForm[_User]):
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
password1: forms.Field
password2: forms.Field
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
Expand All @@ -45,7 +45,7 @@ class UserChangeForm(forms.ModelForm[_User]):
class AuthenticationForm(forms.Form):
username: forms.Field
password: forms.Field
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
request: HttpRequest | None
user_cache: Any
username_field: models.Field
Expand Down Expand Up @@ -81,7 +81,7 @@ class PasswordResetForm(forms.Form):
) -> None: ...

class SetPasswordForm(forms.Form):
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
new_password1: forms.Field
new_password2: forms.Field
user: AbstractBaseUser
Expand All @@ -90,12 +90,12 @@ class SetPasswordForm(forms.Form):
def save(self, commit: bool = ...) -> AbstractBaseUser: ...

class PasswordChangeForm(SetPasswordForm):
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
old_password: forms.Field
def clean_old_password(self) -> str: ...

class AdminPasswordChangeForm(forms.Form):
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
required_css_class: str
password1: forms.Field
password2: forms.Field
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/gis/db/models/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from django.contrib.gis.geos import (
)
from django.core.validators import _ValidatorCallable
from django.db.models.expressions import Combinable
from django.db.models.fields import Field, _ErrorMessagesT, _FieldChoices
from django.db.models.fields import Field, _ErrorMessagesMapping, _FieldChoices
from django.utils.functional import _StrOrPromise

# __set__ value type
Expand Down Expand Up @@ -62,7 +62,7 @@ class BaseSpatialField(Field[_ST, _GT]):
db_column: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
def deconstruct(self) -> Any: ...
def db_type(self, connection: Any) -> Any: ...
Expand Down Expand Up @@ -107,7 +107,7 @@ class GeometryField(BaseSpatialField[_ST, _GT]):
db_column: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
def deconstruct(self) -> Any: ...
def formfield(self, **kwargs: Any) -> Any: ... # type: ignore[override]
Expand Down
1 change: 0 additions & 1 deletion django-stubs/contrib/gis/forms/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from django import forms
class GeometryField(forms.Field):
widget: Any
geom_type: str
default_error_messages: Any
srid: Any
def __init__(self, *, srid: Any | None = ..., geom_type: Any | None = ..., **kwargs: Any) -> None: ...
def to_python(self, value: Any) -> Any: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import Any, TypeVar
from django.core.validators import _ValidatorCallable
from django.db.models import Field, Transform
from django.db.models.expressions import Combinable
from django.db.models.fields import _ErrorMessagesT, _FieldChoices
from django.db.models.fields import _ErrorMessagesDict, _ErrorMessagesMapping, _FieldChoices
from django.db.models.fields.mixins import CheckFieldDefaultMixin
from django.utils.functional import _StrOrPromise

Expand All @@ -18,7 +18,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
_pyi_private_get_type: list[Any]

empty_strings_allowed: bool
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: Field
size: int | None
default_validators: Sequence[_ValidatorCallable]
Expand Down Expand Up @@ -48,7 +48,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
db_column: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[_ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
@property
def description(self) -> str: ... # type: ignore
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/postgres/forms/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ from collections.abc import Sequence
from typing import Any

from django import forms
from django.db.models.fields import _ErrorMessagesT
from django.db.models.fields import _ErrorMessagesDict
from django.forms.fields import _ClassLevelWidgetT
from django.forms.utils import _DataT, _FilesT
from django.forms.widgets import _OptAttrs

from ..utils import prefix_validation_error as prefix_validation_error

class SimpleArrayField(forms.CharField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: forms.Field
delimiter: str
min_length: int | None
Expand Down Expand Up @@ -46,7 +46,7 @@ class SplitArrayWidget(forms.Widget):
def needs_multipart_form(self) -> bool: ... # type: ignore

class SplitArrayField(forms.Field):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: forms.Field
size: int
remove_trailing_nulls: bool
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/forms/hstore.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any

from django import forms
from django.db.models.fields import _ErrorMessagesT
from django.db.models.fields import _ErrorMessagesDict
from django.forms.fields import _ClassLevelWidgetT

class HStoreField(forms.CharField):
widget: _ClassLevelWidgetT
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
def prepare_value(self, value: Any) -> Any: ...
def to_python(self, value: Any) -> dict[str, str | None]: ... # type: ignore
def has_changed(self, initial: Any, data: Any) -> bool: ...
12 changes: 6 additions & 6 deletions django-stubs/contrib/postgres/forms/ranges.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from django import forms
from django.db.models.fields import _ErrorMessagesT
from django.db.models.fields import _ErrorMessagesDict
from django.forms.widgets import MultiWidget, _OptAttrs
from psycopg2.extras import Range

Expand All @@ -13,7 +13,7 @@ class HiddenRangeWidget(RangeWidget):
def __init__(self, attrs: _OptAttrs | None = ...) -> None: ...

class BaseRangeField(forms.MultiValueField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: type[forms.Field]
range_type: type[Range]
hidden_widget: type[forms.Widget]
Expand All @@ -22,21 +22,21 @@ class BaseRangeField(forms.MultiValueField):
def compress(self, values: tuple[Any | None, Any | None]) -> Range | None: ...

class IntegerRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: type[forms.Field]
range_type: type[Range]

class DecimalRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: type[forms.Field]
range_type: type[Range]

class DateTimeRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: type[forms.Field]
range_type: type[Range]

class DateRangeField(BaseRangeField):
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
base_field: type[forms.Field]
range_type: type[Range]
33 changes: 17 additions & 16 deletions django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import decimal
import uuid
from collections.abc import Callable, Iterable, Sequence
from collections.abc import Callable, Iterable, Mapping, Sequence
from datetime import date, time, timedelta
from datetime import datetime as real_datetime
from typing import Any, ClassVar, Generic, Literal, Protocol, TypeVar, overload
Expand Down Expand Up @@ -45,7 +45,8 @@ class _FieldDescriptor(Protocol[_F]):
def field(self) -> _F: ...

_AllLimitChoicesTo: TypeAlias = _LimitChoicesTo | _ChoicesCallable # noqa: Y047
_ErrorMessagesT: TypeAlias = dict[str, Any]
_ErrorMessagesMapping: TypeAlias = Mapping[str, _StrOrPromise]
_ErrorMessagesDict: TypeAlias = dict[str, _StrOrPromise]

# __set__ value type
_ST = TypeVar("_ST", contravariant=True)
Expand Down Expand Up @@ -143,12 +144,12 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
column: str
concrete: bool
default: Any
error_messages: _ErrorMessagesT
error_messages: _ErrorMessagesDict
empty_values: Sequence[Any]
creation_counter: int
auto_creation_counter: int
default_validators: Sequence[validators._ValidatorCallable]
default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
hidden: bool
system_check_removed_details: Any | None
system_check_deprecated_details: Any | None
Expand Down Expand Up @@ -177,7 +178,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
db_tablespace: str | None = ...,
auto_created: bool = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
def __set__(self, instance: Any, value: _ST) -> None: ...
# class access
Expand Down Expand Up @@ -282,7 +283,7 @@ class DecimalField(Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class CharField(Field[_ST, _GT]):
Expand Down Expand Up @@ -313,7 +314,7 @@ class CharField(Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
*,
db_collation: str | None = ...,
) -> None: ...
Expand Down Expand Up @@ -342,7 +343,7 @@ class SlugField(CharField[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
*,
max_length: int | None = ...,
db_index: bool = ...,
Expand Down Expand Up @@ -377,7 +378,7 @@ class URLField(CharField[_ST, _GT]):
db_tablespace: str | None = ...,
auto_created: bool = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class TextField(Field[_ST, _GT]):
Expand Down Expand Up @@ -408,7 +409,7 @@ class TextField(Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
*,
db_collation: str | None = ...,
) -> None: ...
Expand All @@ -431,7 +432,7 @@ class GenericIPAddressField(Field[_ST, _GT]):
_pyi_private_set_type: str | int | Callable[..., Any] | Combinable
_pyi_private_get_type: str

default_error_messages: _ErrorMessagesT
default_error_messages: _ErrorMessagesDict
unpack_ipv4: bool
protocol: str
def __init__(
Expand All @@ -455,7 +456,7 @@ class GenericIPAddressField(Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class DateTimeCheckMixin: ...
Expand Down Expand Up @@ -489,7 +490,7 @@ class DateField(DateTimeCheckMixin, Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
Expand Down Expand Up @@ -519,7 +520,7 @@ class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class DateTimeField(DateField[_ST, _GT]):
Expand Down Expand Up @@ -556,7 +557,7 @@ class UUIDField(Field[_ST, _GT]):
db_tablespace: str | None = ...,
auto_created: bool = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class FilePathField(Field[_ST, _GT]):
Expand Down Expand Up @@ -591,7 +592,7 @@ class FilePathField(Field[_ST, _GT]):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...

class BinaryField(Field[_ST, _GT]):
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/models/fields/files.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from django.core.files.base import File
from django.core.files.images import ImageFile
from django.core.files.storage import Storage
from django.db.models.base import Model
from django.db.models.fields import Field, _ErrorMessagesT, _FieldChoices
from django.db.models.fields import Field, _ErrorMessagesMapping, _FieldChoices
from django.db.models.query_utils import DeferredAttribute
from django.utils._os import _PathCompatible
from django.utils.functional import _StrOrPromise
Expand Down Expand Up @@ -68,7 +68,7 @@ class FileField(Field):
db_comment: str | None = ...,
db_tablespace: str | None = ...,
validators: Iterable[validators._ValidatorCallable] = ...,
error_messages: _ErrorMessagesT | None = ...,
error_messages: _ErrorMessagesMapping | None = ...,
) -> None: ...
# class access
@overload
Expand Down
Loading

0 comments on commit 3a1f139

Please sign in to comment.