Debian Codegraph @

jedi/third_party/typeshed/stdlib/traceback.pyi

raw symbols SCIP
1 import sys
2 from _typeshed import SupportsWrite, Unused
3 from collections.abc import Generator, Iterable, Iterator, Mapping
4 from types import FrameType, TracebackType
5 from typing import Any, ClassVar, Literal, SupportsIndex, overload
6 from typing_extensions import Self, TypeAlias, deprecated
7
8 __all__ = [
9 "extract_stack",
10 "extract_tb",
11 "format_exception",
12 "format_exception_only",
13 "format_list",
14 "format_stack",
15 "format_tb",
16 "print_exc",
17 "format_exc",
18 "print_exception",
19 "print_last",
20 "print_stack",
21 "print_tb",
22 "clear_frames",
23 "FrameSummary",
24 "StackSummary",
25 "TracebackException",
26 "walk_stack",
27 "walk_tb",
28 ]
29
30 if sys.version_info >= (3, 14):
31 __all__ += ["print_list"]
32
33 _FrameSummaryTuple: TypeAlias = tuple[str, int, str, str | None]
34
35 def print_tb(tb: TracebackType | None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ...
36
37 if sys.version_info >= (3, 10):
38 @overload
39 def print_exception(
40 exc: type[BaseException] | None,
41 /,
42 value: BaseException | None = ...,
43 tb: TracebackType | None = ...,
44 limit: int | None = None,
45 file: SupportsWrite[str] | None = None,
46 chain: bool = True,
47 ) -> None: ...
48 @overload
49 def print_exception(
50 exc: BaseException, /, *, limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True
51 ) -> None: ...
52 @overload
53 def format_exception(
54 exc: type[BaseException] | None,
55 /,
56 value: BaseException | None = ...,
57 tb: TracebackType | None = ...,
58 limit: int | None = None,
59 chain: bool = True,
60 ) -> list[str]: ...
61 @overload
62 def format_exception(exc: BaseException, /, *, limit: int | None = None, chain: bool = True) -> list[str]: ...
63
64 else:
65 def print_exception(
66 etype: type[BaseException] | None,
67 value: BaseException | None,
68 tb: TracebackType | None,
69 limit: int | None = None,
70 file: SupportsWrite[str] | None = None,
71 chain: bool = True,
72 ) -> None: ...
73 def format_exception(
74 etype: type[BaseException] | None,
75 value: BaseException | None,
76 tb: TracebackType | None,
77 limit: int | None = None,
78 chain: bool = True,
79 ) -> list[str]: ...
80
81 def print_exc(limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ...
82 def print_last(limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ...
83 def print_stack(f: FrameType | None = None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ...
84 def extract_tb(tb: TracebackType | None, limit: int | None = None) -> StackSummary: ...
85 def extract_stack(f: FrameType | None = None, limit: int | None = None) -> StackSummary: ...
86 def format_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> list[str]: ...
87 def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file: SupportsWrite[str] | None = None) -> None: ...
88
89 if sys.version_info >= (3, 13):
90 @overload
91 def format_exception_only(exc: BaseException | None, /, *, show_group: bool = False) -> list[str]: ...
92 @overload
93 def format_exception_only(exc: Unused, /, value: BaseException | None, *, show_group: bool = False) -> list[str]: ...
94
95 elif sys.version_info >= (3, 10):
96 @overload
97 def format_exception_only(exc: BaseException | None, /) -> list[str]: ...
98 @overload
99 def format_exception_only(exc: Unused, /, value: BaseException | None) -> list[str]: ...
100
101 else:
102 def format_exception_only(etype: type[BaseException] | None, value: BaseException | None) -> list[str]: ...
103
104 def format_exc(limit: int | None = None, chain: bool = True) -> str: ...
105 def format_tb(tb: TracebackType | None, limit: int | None = None) -> list[str]: ...
106 def format_stack(f: FrameType | None = None, limit: int | None = None) -> list[str]: ...
107 def clear_frames(tb: TracebackType | None) -> None: ...
108 def walk_stack(f: FrameType | None) -> Iterator[tuple[FrameType, int]]: ...
109 def walk_tb(tb: TracebackType | None) -> Iterator[tuple[FrameType, int]]: ...
110
111 if sys.version_info >= (3, 11):
112 class _ExceptionPrintContext:
113 def indent(self) -> str: ...
114 def emit(self, text_gen: str | Iterable[str], margin_char: str | None = None) -> Generator[str]: ...
115
116 class TracebackException:
117 __cause__: TracebackException | None
118 __context__: TracebackException | None
119 if sys.version_info >= (3, 11):
120 exceptions: list[TracebackException] | None
121 __suppress_context__: bool
122 if sys.version_info >= (3, 11):
123 __notes__: list[str] | None
124 stack: StackSummary
125
126 # These fields only exist for `SyntaxError`s, but there is no way to express that in the type system.
127 filename: str
128 lineno: str | None
129 if sys.version_info >= (3, 10):
130 end_lineno: str | None
131 text: str
132 offset: int
133 if sys.version_info >= (3, 10):
134 end_offset: int | None
135 msg: str
136
137 if sys.version_info >= (3, 13):
138 @property
139 def exc_type_str(self) -> str: ...
140 @property
141 @deprecated("Deprecated since Python 3.13. Use `exc_type_str` instead.")
142 def exc_type(self) -> type[BaseException] | None: ...
143 else:
144 exc_type: type[BaseException]
145 if sys.version_info >= (3, 13):
146 def __init__(
147 self,
148 exc_type: type[BaseException],
149 exc_value: BaseException,
150 exc_traceback: TracebackType | None,
151 *,
152 limit: int | None = None,
153 lookup_lines: bool = True,
154 capture_locals: bool = False,
155 compact: bool = False,
156 max_group_width: int = 15,
157 max_group_depth: int = 10,
158 save_exc_type: bool = True,
159 _seen: set[int] | None = None,
160 ) -> None: ...
161 elif sys.version_info >= (3, 11):
162 def __init__(
163 self,
164 exc_type: type[BaseException],
165 exc_value: BaseException,
166 exc_traceback: TracebackType | None,
167 *,
168 limit: int | None = None,
169 lookup_lines: bool = True,
170 capture_locals: bool = False,
171 compact: bool = False,
172 max_group_width: int = 15,
173 max_group_depth: int = 10,
174 _seen: set[int] | None = None,
175 ) -> None: ...
176 elif sys.version_info >= (3, 10):
177 def __init__(
178 self,
179 exc_type: type[BaseException],
180 exc_value: BaseException,
181 exc_traceback: TracebackType | None,
182 *,
183 limit: int | None = None,
184 lookup_lines: bool = True,
185 capture_locals: bool = False,
186 compact: bool = False,
187 _seen: set[int] | None = None,
188 ) -> None: ...
189 else:
190 def __init__(
191 self,
192 exc_type: type[BaseException],
193 exc_value: BaseException,
194 exc_traceback: TracebackType | None,
195 *,
196 limit: int | None = None,
197 lookup_lines: bool = True,
198 capture_locals: bool = False,
199 _seen: set[int] | None = None,
200 ) -> None: ...
201
202 if sys.version_info >= (3, 11):
203 @classmethod
204 def from_exception(
205 cls,
206 exc: BaseException,
207 *,
208 limit: int | None = None,
209 lookup_lines: bool = True,
210 capture_locals: bool = False,
211 compact: bool = False,
212 max_group_width: int = 15,
213 max_group_depth: int = 10,
214 ) -> Self: ...
215 elif sys.version_info >= (3, 10):
216 @classmethod
217 def from_exception(
218 cls,
219 exc: BaseException,
220 *,
221 limit: int | None = None,
222 lookup_lines: bool = True,
223 capture_locals: bool = False,
224 compact: bool = False,
225 ) -> Self: ...
226 else:
227 @classmethod
228 def from_exception(
229 cls, exc: BaseException, *, limit: int | None = None, lookup_lines: bool = True, capture_locals: bool = False
230 ) -> Self: ...
231
232 def __eq__(self, other: object) -> bool: ...
233 __hash__: ClassVar[None] # type: ignore[assignment]
234 if sys.version_info >= (3, 11):
235 def format(self, *, chain: bool = True, _ctx: _ExceptionPrintContext | None = None) -> Generator[str]: ...
236 else:
237 def format(self, *, chain: bool = True) -> Generator[str]: ...
238
239 if sys.version_info >= (3, 13):
240 def format_exception_only(self, *, show_group: bool = False, _depth: int = 0) -> Generator[str]: ...
241 else:
242 def format_exception_only(self) -> Generator[str]: ...
243
244 if sys.version_info >= (3, 11):
245 def print(self, *, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ...
246
247 class FrameSummary:
248 if sys.version_info >= (3, 13):
249 __slots__ = (
250 "filename",
251 "lineno",
252 "end_lineno",
253 "colno",
254 "end_colno",
255 "name",
256 "_lines",
257 "_lines_dedented",
258 "locals",
259 "_code",
260 )
261 elif sys.version_info >= (3, 11):
262 __slots__ = ("filename", "lineno", "end_lineno", "colno", "end_colno", "name", "_line", "locals")
263 else:
264 __slots__ = ("filename", "lineno", "name", "_line", "locals")
265 if sys.version_info >= (3, 11):
266 def __init__(
267 self,
268 filename: str,
269 lineno: int | None,
270 name: str,
271 *,
272 lookup_line: bool = True,
273 locals: Mapping[str, str] | None = None,
274 line: str | None = None,
275 end_lineno: int | None = None,
276 colno: int | None = None,
277 end_colno: int | None = None,
278 ) -> None: ...
279 end_lineno: int | None
280 colno: int | None
281 end_colno: int | None
282 else:
283 def __init__(
284 self,
285 filename: str,
286 lineno: int | None,
287 name: str,
288 *,
289 lookup_line: bool = True,
290 locals: Mapping[str, str] | None = None,
291 line: str | None = None,
292 ) -> None: ...
293 filename: str
294 lineno: int | None
295 name: str
296 locals: dict[str, str] | None
297 @property
298 def line(self) -> str | None: ...
299 @overload
300 def __getitem__(self, pos: Literal[0]) -> str: ...
301 @overload
302 def __getitem__(self, pos: Literal[1]) -> int: ...
303 @overload
304 def __getitem__(self, pos: Literal[2]) -> str: ...
305 @overload
306 def __getitem__(self, pos: Literal[3]) -> str | None: ...
307 @overload
308 def __getitem__(self, pos: SupportsIndex) -> Any: ...
309 @overload
310 def __getitem__(self, pos: slice[SupportsIndex | None]) -> tuple[Any, ...]: ...
311 def __iter__(self) -> Iterator[Any]: ...
312 def __eq__(self, other: object) -> bool: ...
313 def __len__(self) -> Literal[4]: ...
314 __hash__: ClassVar[None] # type: ignore[assignment]
315
316 class StackSummary(list[FrameSummary]):
317 @classmethod
318 def extract(
319 cls,
320 frame_gen: Iterable[tuple[FrameType, int]],
321 *,
322 limit: int | None = None,
323 lookup_lines: bool = True,
324 capture_locals: bool = False,
325 ) -> StackSummary: ...
326 @classmethod
327 def from_list(cls, a_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> StackSummary: ...
328 if sys.version_info >= (3, 11):
329 def format_frame_summary(self, frame_summary: FrameSummary) -> str: ...
330
331 def format(self) -> list[str]: ...