utils.pyi 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import sys
  2. from ast import AST
  3. from typing import (
  4. Any,
  5. Callable,
  6. List,
  7. Mapping,
  8. Optional,
  9. overload,
  10. Sequence,
  11. Tuple,
  12. TypeVar,
  13. Union,
  14. )
  15. from numpy import ndarray, generic
  16. from numpy.core.numerictypes import (
  17. issubclass_ as issubclass_,
  18. issubdtype as issubdtype,
  19. issubsctype as issubsctype,
  20. )
  21. if sys.version_info >= (3, 8):
  22. from typing import Protocol
  23. else:
  24. from typing_extensions import Protocol
  25. _T_contra = TypeVar("_T_contra", contravariant=True)
  26. _FuncType = TypeVar("_FuncType", bound=Callable[..., Any])
  27. # A file-like object opened in `w` mode
  28. class _SupportsWrite(Protocol[_T_contra]):
  29. def write(self, __s: _T_contra) -> Any: ...
  30. __all__: List[str]
  31. class _Deprecate:
  32. old_name: Optional[str]
  33. new_name: Optional[str]
  34. message: Optional[str]
  35. def __init__(
  36. self,
  37. old_name: Optional[str] = ...,
  38. new_name: Optional[str] = ...,
  39. message: Optional[str] = ...,
  40. ) -> None: ...
  41. # NOTE: `__call__` can in principle take arbitrary `*args` and `**kwargs`,
  42. # even though they aren't used for anything
  43. def __call__(self, func: _FuncType) -> _FuncType: ...
  44. def get_include() -> str: ...
  45. @overload
  46. def deprecate(
  47. *,
  48. old_name: Optional[str] = ...,
  49. new_name: Optional[str] = ...,
  50. message: Optional[str] = ...,
  51. ) -> _Deprecate: ...
  52. @overload
  53. def deprecate(
  54. __func: _FuncType,
  55. old_name: Optional[str] = ...,
  56. new_name: Optional[str] = ...,
  57. message: Optional[str] = ...,
  58. ) -> _FuncType: ...
  59. def deprecate_with_doc(msg: Optional[str]) -> _Deprecate: ...
  60. # NOTE: In practice `byte_bounds` can (potentially) take any object
  61. # implementing the `__array_interface__` protocol. The caveat is
  62. # that certain keys, marked as optional in the spec, must be present for
  63. # `byte_bounds`. This concerns `"strides"` and `"data"`.
  64. def byte_bounds(a: Union[generic, ndarray[Any, Any]]) -> Tuple[int, int]: ...
  65. def who(vardict: Optional[Mapping[str, ndarray[Any, Any]]] = ...) -> None: ...
  66. def info(
  67. object: object = ...,
  68. maxwidth: int = ...,
  69. output: Optional[_SupportsWrite[str]] = ...,
  70. toplevel: str = ...,
  71. ) -> None: ...
  72. def source(
  73. object: object,
  74. output: Optional[_SupportsWrite[str]] = ...,
  75. ) -> None: ...
  76. def lookfor(
  77. what: str,
  78. module: Union[None, str, Sequence[str]] = ...,
  79. import_modules: bool = ...,
  80. regenerate: bool = ...,
  81. output: Optional[_SupportsWrite[str]] =...,
  82. ) -> None: ...
  83. def safe_eval(source: Union[str, AST]) -> Any: ...