/ lib / attr / validators.pyi
validators.pyi
 1  from typing import (
 2      Any,
 3      AnyStr,
 4      Callable,
 5      Container,
 6      ContextManager,
 7      Iterable,
 8      List,
 9      Mapping,
10      Match,
11      Optional,
12      Pattern,
13      Tuple,
14      Type,
15      TypeVar,
16      Union,
17      overload,
18  )
19  
20  from . import _ValidatorType
21  
22  _T = TypeVar("_T")
23  _T1 = TypeVar("_T1")
24  _T2 = TypeVar("_T2")
25  _T3 = TypeVar("_T3")
26  _I = TypeVar("_I", bound=Iterable)
27  _K = TypeVar("_K")
28  _V = TypeVar("_V")
29  _M = TypeVar("_M", bound=Mapping)
30  
31  def set_disabled(run: bool) -> None: ...
32  def get_disabled() -> bool: ...
33  def disabled() -> ContextManager[None]: ...
34  
35  # To be more precise on instance_of use some overloads.
36  # If there are more than 3 items in the tuple then we fall back to Any
37  @overload
38  def instance_of(type: Type[_T]) -> _ValidatorType[_T]: ...
39  @overload
40  def instance_of(type: Tuple[Type[_T]]) -> _ValidatorType[_T]: ...
41  @overload
42  def instance_of(
43      type: Tuple[Type[_T1], Type[_T2]]
44  ) -> _ValidatorType[Union[_T1, _T2]]: ...
45  @overload
46  def instance_of(
47      type: Tuple[Type[_T1], Type[_T2], Type[_T3]]
48  ) -> _ValidatorType[Union[_T1, _T2, _T3]]: ...
49  @overload
50  def instance_of(type: Tuple[type, ...]) -> _ValidatorType[Any]: ...
51  def provides(interface: Any) -> _ValidatorType[Any]: ...
52  def optional(
53      validator: Union[_ValidatorType[_T], List[_ValidatorType[_T]]]
54  ) -> _ValidatorType[Optional[_T]]: ...
55  def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
56  def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
57  def matches_re(
58      regex: Union[Pattern[AnyStr], AnyStr],
59      flags: int = ...,
60      func: Optional[
61          Callable[[AnyStr, AnyStr, int], Optional[Match[AnyStr]]]
62      ] = ...,
63  ) -> _ValidatorType[AnyStr]: ...
64  def deep_iterable(
65      member_validator: _ValidatorType[_T],
66      iterable_validator: Optional[_ValidatorType[_I]] = ...,
67  ) -> _ValidatorType[_I]: ...
68  def deep_mapping(
69      key_validator: _ValidatorType[_K],
70      value_validator: _ValidatorType[_V],
71      mapping_validator: Optional[_ValidatorType[_M]] = ...,
72  ) -> _ValidatorType[_M]: ...
73  def is_callable() -> _ValidatorType[_T]: ...
74  def lt(val: _T) -> _ValidatorType[_T]: ...
75  def le(val: _T) -> _ValidatorType[_T]: ...
76  def ge(val: _T) -> _ValidatorType[_T]: ...
77  def gt(val: _T) -> _ValidatorType[_T]: ...
78  def max_len(length: int) -> _ValidatorType[_T]: ...