validators.pyi 2.2 KB

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