25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

87 satır
2.5 KiB

  1. from types import UnionType
  2. from typing import (
  3. Any,
  4. AnyStr,
  5. Callable,
  6. Container,
  7. ContextManager,
  8. Iterable,
  9. Mapping,
  10. Match,
  11. Pattern,
  12. TypeVar,
  13. overload,
  14. )
  15. from attrs import _ValidatorType
  16. from attrs import _ValidatorArgType
  17. _T = TypeVar("_T")
  18. _T1 = TypeVar("_T1")
  19. _T2 = TypeVar("_T2")
  20. _T3 = TypeVar("_T3")
  21. _I = TypeVar("_I", bound=Iterable)
  22. _K = TypeVar("_K")
  23. _V = TypeVar("_V")
  24. _M = TypeVar("_M", bound=Mapping)
  25. def set_disabled(run: bool) -> None: ...
  26. def get_disabled() -> bool: ...
  27. def disabled() -> ContextManager[None]: ...
  28. # To be more precise on instance_of use some overloads.
  29. # If there are more than 3 items in the tuple then we fall back to Any
  30. @overload
  31. def instance_of(type: type[_T]) -> _ValidatorType[_T]: ...
  32. @overload
  33. def instance_of(type: tuple[type[_T]]) -> _ValidatorType[_T]: ...
  34. @overload
  35. def instance_of(
  36. type: tuple[type[_T1], type[_T2]],
  37. ) -> _ValidatorType[_T1 | _T2]: ...
  38. @overload
  39. def instance_of(
  40. type: tuple[type[_T1], type[_T2], type[_T3]],
  41. ) -> _ValidatorType[_T1 | _T2 | _T3]: ...
  42. @overload
  43. def instance_of(type: tuple[type, ...]) -> _ValidatorType[Any]: ...
  44. @overload
  45. def instance_of(type: UnionType) -> _ValidatorType[Any]: ...
  46. def optional(
  47. validator: (
  48. _ValidatorType[_T]
  49. | list[_ValidatorType[_T]]
  50. | tuple[_ValidatorType[_T]]
  51. ),
  52. ) -> _ValidatorType[_T | None]: ...
  53. def in_(options: Container[_T]) -> _ValidatorType[_T]: ...
  54. def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...
  55. def matches_re(
  56. regex: Pattern[AnyStr] | AnyStr,
  57. flags: int = ...,
  58. func: Callable[[AnyStr, AnyStr, int], Match[AnyStr] | None] | None = ...,
  59. ) -> _ValidatorType[AnyStr]: ...
  60. def deep_iterable(
  61. member_validator: _ValidatorArgType[_T],
  62. iterable_validator: _ValidatorType[_I] | None = ...,
  63. ) -> _ValidatorType[_I]: ...
  64. def deep_mapping(
  65. key_validator: _ValidatorType[_K],
  66. value_validator: _ValidatorType[_V],
  67. mapping_validator: _ValidatorType[_M] | None = ...,
  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]: ...
  75. def min_len(length: int) -> _ValidatorType[_T]: ...
  76. def not_(
  77. validator: _ValidatorType[_T],
  78. *,
  79. msg: str | None = None,
  80. exc_types: type[Exception] | Iterable[type[Exception]] = ...,
  81. ) -> _ValidatorType[_T]: ...
  82. def or_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ...