Skip to content

Commit

Permalink
Allow message being a _StrPromise object for RegexValidator.
Browse files Browse the repository at this point in the history
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 <p359101898@gmail.com>
  • Loading branch information
PIG208 committed Aug 19, 2022
1 parent e1b69bc commit e213d75
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django-stubs/core/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from re import RegexFlag
from typing import Any, Callable, Collection, Dict, List, Optional, Pattern, Sequence, Sized, Tuple, Union

from django.core.files.base import File
from django.utils.functional import _StrPromise

EMPTY_VALUES: Any

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

class RegexValidator:
regex: _Regex = ... # Pattern[str] on instance, but may be str on class definition
message: str = ...
message: Union[str, _StrPromise] = ...
code: str = ...
inverse_match: bool = ...
flags: int = ...
def __init__(
self,
regex: Optional[_Regex] = ...,
message: Optional[str] = ...,
message: Union[str, _StrPromise, None] = ...,
code: Optional[str] = ...,
inverse_match: Optional[bool] = ...,
flags: Optional[RegexFlag] = ...,
Expand Down

0 comments on commit e213d75

Please sign in to comment.