Skip to content

Commit 6e66d4e

Browse files
committed
Allow message being a _StrPromise object for RegexValidator.
One intended usage of lazystr is to postpone the translation of the error message of a validation error. It is possible that we pass a Promise (specifically _StrPromise) and only evaluate it when a ValidationError is raised. Signed-off-by: Zixuan James Li <[email protected]>
1 parent d8f60bb commit 6e66d4e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

django-stubs/core/validators.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from re import RegexFlag
33
from typing import Any, Callable, Collection, Dict, List, Optional, Pattern, Sequence, Sized, Tuple, Union
44

55
from django.core.files.base import File
6+
from django.utils.functional import _StrPromise
67

78
EMPTY_VALUES: Any
89

@@ -11,14 +12,14 @@ _ValidatorCallable = Callable[[Any], None]
1112

1213
class RegexValidator:
1314
regex: _Regex = ... # Pattern[str] on instance, but may be str on class definition
14-
message: str = ...
15+
message: Union[str, _StrPromise] = ...
1516
code: str = ...
1617
inverse_match: bool = ...
1718
flags: int = ...
1819
def __init__(
1920
self,
2021
regex: Optional[_Regex] = ...,
21-
message: Optional[str] = ...,
22+
message: Union[str, _StrPromise, None] = ...,
2223
code: Optional[str] = ...,
2324
inverse_match: Optional[bool] = ...,
2425
flags: Optional[RegexFlag] = ...,

0 commit comments

Comments
 (0)