utils.pyi 2.3 KB

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