2 from _typeshed import SupportsWrite
3 from types import FrameType, TracebackType
4 from typing import IO, Any, Generator, Iterable, Iterator, List, Mapping, Optional, Tuple, Type
6 _PT = Tuple[str, int, str, Optional[str]]
8 def print_tb(tb: TracebackType | None, limit: int | None = ..., file: IO[str] | None = ...) -> None: ...
10 if sys.version_info >= (3, 10):
12 __exc: Type[BaseException] | None,
13 value: BaseException | None = ...,
14 tb: TracebackType | None = ...,
15 limit: int | None = ...,
16 file: IO[str] | None = ...,
22 etype: Type[BaseException] | None,
23 value: BaseException | None,
24 tb: TracebackType | None,
25 limit: int | None = ...,
26 file: IO[str] | None = ...,
30 def print_exc(limit: int | None = ..., file: IO[str] | None = ..., chain: bool = ...) -> None: ...
31 def print_last(limit: int | None = ..., file: IO[str] | None = ..., chain: bool = ...) -> None: ...
32 def print_stack(f: FrameType | None = ..., limit: int | None = ..., file: IO[str] | None = ...) -> None: ...
33 def extract_tb(tb: TracebackType | None, limit: int | None = ...) -> StackSummary: ...
34 def extract_stack(f: FrameType | None = ..., limit: int | None = ...) -> StackSummary: ...
35 def format_list(extracted_list: list[FrameSummary]) -> list[str]: ...
38 def print_list(extracted_list: list[FrameSummary], file: SupportsWrite[str] | None = ...) -> None: ...
40 if sys.version_info >= (3, 10):
41 def format_exception_only(__exc: Type[BaseException] | None, value: BaseException | None = ...) -> list[str]: ...
44 def format_exception_only(etype: Type[BaseException] | None, value: BaseException | None) -> list[str]: ...
46 if sys.version_info >= (3, 10):
48 __exc: Type[BaseException] | None,
49 value: BaseException | None = ...,
50 tb: TracebackType | None = ...,
51 limit: int | None = ...,
57 etype: Type[BaseException] | None,
58 value: BaseException | None,
59 tb: TracebackType | None,
60 limit: int | None = ...,
64 def format_exc(limit: int | None = ..., chain: bool = ...) -> str: ...
65 def format_tb(tb: TracebackType | None, limit: int | None = ...) -> list[str]: ...
66 def format_stack(f: FrameType | None = ..., limit: int | None = ...) -> list[str]: ...
67 def clear_frames(tb: TracebackType) -> None: ...
68 def walk_stack(f: FrameType | None) -> Iterator[tuple[FrameType, int]]: ...
69 def walk_tb(tb: TracebackType | None) -> Iterator[tuple[FrameType, int]]: ...
71 class TracebackException:
72 __cause__: TracebackException
73 __context__: TracebackException
74 __suppress_context__: bool
76 exc_type: Type[BaseException]
82 if sys.version_info >= (3, 10):
85 exc_type: Type[BaseException],
86 exc_value: BaseException,
87 exc_traceback: TracebackType,
89 limit: int | None = ...,
90 lookup_lines: bool = ...,
91 capture_locals: bool = ...,
93 _seen: set[int] | None = ...,
100 limit: int | None = ...,
101 lookup_lines: bool = ...,
102 capture_locals: bool = ...,
104 ) -> TracebackException: ...
108 exc_type: Type[BaseException],
109 exc_value: BaseException,
110 exc_traceback: TracebackType,
112 limit: int | None = ...,
113 lookup_lines: bool = ...,
114 capture_locals: bool = ...,
115 _seen: set[int] | None = ...,
119 cls, exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ...
120 ) -> TracebackException: ...
121 def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ...
122 def format_exception_only(self) -> Generator[str, None, None]: ...
124 class FrameSummary(Iterable[Any]):
129 locals: dict[str, str] | None
136 lookup_line: bool = ...,
137 locals: Mapping[str, str] | None = ...,
138 line: str | None = ...,
140 # TODO: more precise typing for __getitem__ and __iter__,
141 # for a namedtuple-like view on (filename, lineno, name, str).
142 def __getitem__(self, i: int) -> Any: ...
143 def __iter__(self) -> Iterator[Any]: ...
145 class StackSummary(List[FrameSummary]):
149 frame_gen: Iterable[tuple[FrameType, int]],
151 limit: int | None = ...,
152 lookup_lines: bool = ...,
153 capture_locals: bool = ...,
154 ) -> StackSummary: ...
156 def from_list(cls, a_list: list[_PT]) -> StackSummary: ...
157 def format(self) -> list[str]: ...