validators.pyi 1.8 KB

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