__init__.pyi 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import sys
  2. from asyncio import AbstractEventLoop
  3. from datetime import datetime, time, timedelta
  4. from logging import Handler
  5. from multiprocessing.context import BaseContext
  6. from types import TracebackType
  7. from typing import (
  8. Any,
  9. BinaryIO,
  10. Callable,
  11. Dict,
  12. Generator,
  13. Generic,
  14. List,
  15. NamedTuple,
  16. NewType,
  17. Optional,
  18. Pattern,
  19. Sequence,
  20. TextIO,
  21. Tuple,
  22. Type,
  23. TypeVar,
  24. Union,
  25. overload,
  26. )
  27. if sys.version_info >= (3, 6):
  28. from typing import Awaitable
  29. else:
  30. from typing_extensions import Awaitable
  31. if sys.version_info >= (3, 6):
  32. from os import PathLike
  33. from typing import ContextManager
  34. PathLikeStr = PathLike[str]
  35. else:
  36. from pathlib import PurePath as PathLikeStr
  37. from typing_extensions import ContextManager
  38. if sys.version_info >= (3, 8):
  39. from typing import Protocol, TypedDict
  40. else:
  41. from typing_extensions import Protocol, TypedDict
  42. _T = TypeVar("_T")
  43. _F = TypeVar("_F", bound=Callable[..., Any])
  44. ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]
  45. class _GeneratorContextManager(ContextManager[_T], Generic[_T]):
  46. def __call__(self, func: _F) -> _F: ...
  47. def __exit__(
  48. self,
  49. typ: Optional[Type[BaseException]],
  50. value: Optional[BaseException],
  51. traceback: Optional[TracebackType],
  52. ) -> Optional[bool]: ...
  53. Catcher = NewType("Catcher", _GeneratorContextManager[None])
  54. Contextualizer = NewType("Contextualizer", _GeneratorContextManager[None])
  55. AwaitableCompleter = Awaitable[None]
  56. class Level(NamedTuple):
  57. name: str
  58. no: int
  59. color: str
  60. icon: str
  61. class _RecordAttribute:
  62. def __format__(self, spec: str) -> str: ...
  63. class RecordFile(_RecordAttribute):
  64. name: str
  65. path: str
  66. class RecordLevel(_RecordAttribute):
  67. name: str
  68. no: int
  69. icon: str
  70. class RecordThread(_RecordAttribute):
  71. id: int
  72. name: str
  73. class RecordProcess(_RecordAttribute):
  74. id: int
  75. name: str
  76. class RecordException(NamedTuple):
  77. type: Optional[Type[BaseException]]
  78. value: Optional[BaseException]
  79. traceback: Optional[TracebackType]
  80. class Record(TypedDict):
  81. elapsed: timedelta
  82. exception: Optional[RecordException]
  83. extra: Dict[Any, Any]
  84. file: RecordFile
  85. function: str
  86. level: RecordLevel
  87. line: int
  88. message: str
  89. module: str
  90. name: Optional[str]
  91. process: RecordProcess
  92. thread: RecordThread
  93. time: datetime
  94. class Message(str):
  95. record: Record
  96. class Writable(Protocol):
  97. def write(self, message: Message) -> None: ...
  98. FilterDict = Dict[Optional[str], Union[str, int, bool]]
  99. FilterFunction = Callable[[Record], bool]
  100. FormatFunction = Callable[[Record], str]
  101. PatcherFunction = Callable[[Record], None]
  102. RotationFunction = Callable[[Message, TextIO], bool]
  103. RetentionFunction = Callable[[List[str]], None]
  104. CompressionFunction = Callable[[str], None]
  105. StandardOpener = Callable[[str, int], int]
  106. class BasicHandlerConfig(TypedDict, total=False):
  107. sink: Union[TextIO, Writable, Callable[[Message], None], Handler]
  108. level: Union[str, int]
  109. format: Union[str, FormatFunction]
  110. filter: Optional[Union[str, FilterFunction, FilterDict]]
  111. colorize: Optional[bool]
  112. serialize: bool
  113. backtrace: bool
  114. diagnose: bool
  115. enqueue: bool
  116. catch: bool
  117. class FileHandlerConfig(TypedDict, total=False):
  118. sink: Union[str, PathLikeStr]
  119. level: Union[str, int]
  120. format: Union[str, FormatFunction]
  121. filter: Optional[Union[str, FilterFunction, FilterDict]]
  122. colorize: Optional[bool]
  123. serialize: bool
  124. backtrace: bool
  125. diagnose: bool
  126. enqueue: bool
  127. catch: bool
  128. rotation: Optional[Union[str, int, time, timedelta, RotationFunction]]
  129. retention: Optional[Union[str, int, timedelta, RetentionFunction]]
  130. compression: Optional[Union[str, CompressionFunction]]
  131. delay: bool
  132. watch: bool
  133. mode: str
  134. buffering: int
  135. encoding: str
  136. errors: Optional[str]
  137. newline: Optional[str]
  138. closefd: bool
  139. opener: Optional[StandardOpener]
  140. class AsyncHandlerConfig(TypedDict, total=False):
  141. sink: Callable[[Message], Awaitable[None]]
  142. level: Union[str, int]
  143. format: Union[str, FormatFunction]
  144. filter: Optional[Union[str, FilterFunction, FilterDict]]
  145. colorize: Optional[bool]
  146. serialize: bool
  147. backtrace: bool
  148. diagnose: bool
  149. enqueue: bool
  150. catch: bool
  151. context: Optional[Union[str, BaseContext]]
  152. loop: Optional[AbstractEventLoop]
  153. HandlerConfig = Union[BasicHandlerConfig, FileHandlerConfig, AsyncHandlerConfig]
  154. class LevelConfig(TypedDict, total=False):
  155. name: str
  156. no: int
  157. color: str
  158. icon: str
  159. ActivationConfig = Tuple[Optional[str], bool]
  160. class Logger:
  161. @overload
  162. def add(
  163. self,
  164. sink: Union[TextIO, Writable, Callable[[Message], None], Handler],
  165. *,
  166. level: Union[str, int] = ...,
  167. format: Union[str, FormatFunction] = ...,
  168. filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,
  169. colorize: Optional[bool] = ...,
  170. serialize: bool = ...,
  171. backtrace: bool = ...,
  172. diagnose: bool = ...,
  173. enqueue: bool = ...,
  174. context: Optional[Union[str, BaseContext]] = ...,
  175. catch: bool = ...
  176. ) -> int: ...
  177. @overload
  178. def add(
  179. self,
  180. sink: Callable[[Message], Awaitable[None]],
  181. *,
  182. level: Union[str, int] = ...,
  183. format: Union[str, FormatFunction] = ...,
  184. filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,
  185. colorize: Optional[bool] = ...,
  186. serialize: bool = ...,
  187. backtrace: bool = ...,
  188. diagnose: bool = ...,
  189. enqueue: bool = ...,
  190. catch: bool = ...,
  191. context: Optional[Union[str, BaseContext]] = ...,
  192. loop: Optional[AbstractEventLoop] = ...
  193. ) -> int: ...
  194. @overload
  195. def add(
  196. self,
  197. sink: Union[str, PathLikeStr],
  198. *,
  199. level: Union[str, int] = ...,
  200. format: Union[str, FormatFunction] = ...,
  201. filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,
  202. colorize: Optional[bool] = ...,
  203. serialize: bool = ...,
  204. backtrace: bool = ...,
  205. diagnose: bool = ...,
  206. enqueue: bool = ...,
  207. context: Optional[Union[str, BaseContext]] = ...,
  208. catch: bool = ...,
  209. rotation: Optional[Union[str, int, time, timedelta, RotationFunction]] = ...,
  210. retention: Optional[Union[str, int, timedelta, RetentionFunction]] = ...,
  211. compression: Optional[Union[str, CompressionFunction]] = ...,
  212. delay: bool = ...,
  213. watch: bool = ...,
  214. mode: str = ...,
  215. buffering: int = ...,
  216. encoding: str = ...,
  217. errors: Optional[str] = ...,
  218. newline: Optional[str] = ...,
  219. closefd: bool = ...,
  220. opener: Optional[StandardOpener] = ...,
  221. ) -> int: ...
  222. def remove(self, handler_id: Optional[int] = ...) -> None: ...
  223. def complete(self) -> AwaitableCompleter: ...
  224. @overload
  225. def catch(
  226. self,
  227. exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = ...,
  228. *,
  229. level: Union[str, int] = ...,
  230. reraise: bool = ...,
  231. onerror: Optional[Callable[[BaseException], None]] = ...,
  232. exclude: Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]] = ...,
  233. default: Any = ...,
  234. message: str = ...
  235. ) -> Catcher: ...
  236. @overload
  237. def catch(self, function: _F) -> _F: ...
  238. def opt(
  239. self,
  240. *,
  241. exception: Optional[Union[bool, ExcInfo, BaseException]] = ...,
  242. record: bool = ...,
  243. lazy: bool = ...,
  244. colors: bool = ...,
  245. raw: bool = ...,
  246. capture: bool = ...,
  247. depth: int = ...,
  248. ansi: bool = ...
  249. ) -> Logger: ...
  250. def bind(__self, **kwargs: Any) -> Logger: ... # noqa: N805
  251. def contextualize(__self, **kwargs: Any) -> Contextualizer: ... # noqa: N805
  252. def patch(self, patcher: PatcherFunction) -> Logger: ...
  253. @overload
  254. def level(self, name: str) -> Level: ...
  255. @overload
  256. def level(
  257. self, name: str, no: int = ..., color: Optional[str] = ..., icon: Optional[str] = ...
  258. ) -> Level: ...
  259. @overload
  260. def level(
  261. self,
  262. name: str,
  263. no: Optional[int] = ...,
  264. color: Optional[str] = ...,
  265. icon: Optional[str] = ...,
  266. ) -> Level: ...
  267. def disable(self, name: Optional[str]) -> None: ...
  268. def enable(self, name: Optional[str]) -> None: ...
  269. def configure(
  270. self,
  271. *,
  272. handlers: Optional[Sequence[HandlerConfig]] = ...,
  273. levels: Optional[Sequence[LevelConfig]] = ...,
  274. extra: Optional[Dict[Any, Any]] = ...,
  275. patcher: Optional[PatcherFunction] = ...,
  276. activation: Optional[Sequence[ActivationConfig]] = ...
  277. ) -> List[int]: ...
  278. # @staticmethod cannot be used with @overload in mypy (python/mypy#7781).
  279. # However Logger is not exposed and logger is an instance of Logger
  280. # so for type checkers it is all the same whether it is defined here
  281. # as a static method or an instance method.
  282. @overload
  283. def parse(
  284. self,
  285. file: Union[str, PathLikeStr, TextIO],
  286. pattern: Union[str, Pattern[str]],
  287. *,
  288. cast: Union[Dict[str, Callable[[str], Any]], Callable[[Dict[str, str]], None]] = ...,
  289. chunk: int = ...
  290. ) -> Generator[Dict[str, Any], None, None]: ...
  291. @overload
  292. def parse(
  293. self,
  294. file: BinaryIO,
  295. pattern: Union[bytes, Pattern[bytes]],
  296. *,
  297. cast: Union[Dict[str, Callable[[bytes], Any]], Callable[[Dict[str, bytes]], None]] = ...,
  298. chunk: int = ...
  299. ) -> Generator[Dict[str, Any], None, None]: ...
  300. @overload
  301. def trace(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  302. @overload
  303. def trace(__self, __message: Any) -> None: ... # noqa: N805
  304. @overload
  305. def debug(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  306. @overload
  307. def debug(__self, __message: Any) -> None: ... # noqa: N805
  308. @overload
  309. def info(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  310. @overload
  311. def info(__self, __message: Any) -> None: ... # noqa: N805
  312. @overload
  313. def success(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  314. @overload
  315. def success(__self, __message: Any) -> None: ... # noqa: N805
  316. @overload
  317. def warning(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  318. @overload
  319. def warning(__self, __message: Any) -> None: ... # noqa: N805
  320. @overload
  321. def error(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  322. @overload
  323. def error(__self, __message: Any) -> None: ... # noqa: N805
  324. @overload
  325. def critical(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  326. @overload
  327. def critical(__self, __message: Any) -> None: ... # noqa: N805
  328. @overload
  329. def exception(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805
  330. @overload
  331. def exception(__self, __message: Any) -> None: ... # noqa: N805
  332. @overload
  333. def log(
  334. __self, __level: Union[int, str], __message: str, *args: Any, **kwargs: Any # noqa: N805
  335. ) -> None: ...
  336. @overload
  337. def log(__self, __level: Union[int, str], __message: Any) -> None: ... # noqa: N805
  338. def start(self, *args: Any, **kwargs: Any) -> int: ...
  339. def stop(self, *args: Any, **kwargs: Any) -> None: ...
  340. logger: Logger