From 79d34d6f46e7c24688fdb64de4b6a037dcf518a3 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Wed, 8 Dec 2021 14:09:20 +0200 Subject: [PATCH] Add ValidationError type hints (#767) --- django-stubs/core/exceptions.pyi | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/django-stubs/core/exceptions.pyi b/django-stubs/core/exceptions.pyi index 6d2d7a8..f454a81 100644 --- a/django-stubs/core/exceptions.pyi +++ b/django-stubs/core/exceptions.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Iterator, List, Mapping, Optional, Tuple, Union +from typing import Any, Dict, Iterator, List, Literal, Mapping, Optional, Tuple, Union from django.forms.utils import ErrorDict @@ -24,15 +24,20 @@ class MiddlewareNotUsed(Exception): ... class ImproperlyConfigured(Exception): ... class FieldError(Exception): ... -NON_FIELD_ERRORS: str +NON_FIELD_ERRORS: Literal["__all__"] class ValidationError(Exception): - error_dict: Any = ... - error_list: Any = ... - message: Any = ... - code: Any = ... - params: Any = ... - def __init__(self, message: Any, code: Optional[str] = ..., params: Optional[Mapping[str, Any]] = ...) -> None: ... + error_dict: Dict[str, ValidationError] = ... + error_list: List[ValidationError] = ... + message: str = ... + code: Optional[str] = ... + params: Optional[Mapping[str, Any]] = ... + def __init__( + self, + message: Union[str, ValidationError, Dict[str, Any], List[Any]], + code: Optional[str] = ..., + params: Optional[Mapping[str, Any]] = ..., + ) -> None: ... @property def message_dict(self) -> Dict[str, List[str]]: ... @property