Debian Codegraph @

jedi/third_party/typeshed/stdlib/dis.pyi

raw symbols SCIP
1 import sys
2 import types
3 from collections.abc import Callable, Iterator
4 from opcode import * # `dis` re-exports it as a part of public API
5 from typing import IO, Any, Final, NamedTuple, overload
6 from typing_extensions import Self, TypeAlias, deprecated, disjoint_base
7
8 __all__ = [
9 "code_info",
10 "dis",
11 "disassemble",
12 "distb",
13 "disco",
14 "findlinestarts",
15 "findlabels",
16 "show_code",
17 "get_instructions",
18 "Instruction",
19 "Bytecode",
20 "cmp_op",
21 "hasconst",
22 "hasname",
23 "hasjrel",
24 "hasjabs",
25 "haslocal",
26 "hascompare",
27 "hasfree",
28 "opname",
29 "opmap",
30 "HAVE_ARGUMENT",
31 "EXTENDED_ARG",
32 "stack_effect",
33 ]
34 if sys.version_info >= (3, 13):
35 __all__ += ["hasjump"]
36
37 if sys.version_info >= (3, 12):
38 __all__ += ["hasarg", "hasexc"]
39 else:
40 __all__ += ["hasnargs"]
41
42 # Strictly this should not have to include Callable, but mypy doesn't use FunctionType
43 # for functions (python/mypy#3171)
44 _HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any]
45
46 if sys.version_info >= (3, 11):
47 class Positions(NamedTuple):
48 lineno: int | None = None
49 end_lineno: int | None = None
50 col_offset: int | None = None
51 end_col_offset: int | None = None
52
53 if sys.version_info >= (3, 13):
54 class _Instruction(NamedTuple):
55 opname: str
56 opcode: int
57 arg: int | None
58 argval: Any
59 argrepr: str
60 offset: int
61 start_offset: int
62 starts_line: bool
63 line_number: int | None
64 label: int | None = None
65 positions: Positions | None = None
66 cache_info: list[tuple[str, int, Any]] | None = None
67
68 elif sys.version_info >= (3, 11):
69 class _Instruction(NamedTuple):
70 opname: str
71 opcode: int
72 arg: int | None
73 argval: Any
74 argrepr: str
75 offset: int
76 starts_line: int | None
77 is_jump_target: bool
78 positions: Positions | None = None
79
80 else:
81 class _Instruction(NamedTuple):
82 opname: str
83 opcode: int
84 arg: int | None
85 argval: Any
86 argrepr: str
87 offset: int
88 starts_line: int | None
89 is_jump_target: bool
90
91 if sys.version_info >= (3, 12):
92 class Instruction(_Instruction):
93 if sys.version_info < (3, 13):
94 def _disassemble(self, lineno_width: int = 3, mark_as_current: bool = False, offset_width: int = 4) -> str: ...
95 if sys.version_info >= (3, 13):
96 @property
97 def oparg(self) -> int: ...
98 @property
99 def baseopcode(self) -> int: ...
100 @property
101 def baseopname(self) -> str: ...
102 @property
103 def cache_offset(self) -> int: ...
104 @property
105 def end_offset(self) -> int: ...
106 @property
107 def jump_target(self) -> int: ...
108 @property
109 def is_jump_target(self) -> bool: ...
110 if sys.version_info >= (3, 14):
111 @staticmethod
112 def make(
113 opname: str,
114 arg: int | None,
115 argval: Any,
116 argrepr: str,
117 offset: int,
118 start_offset: int,
119 starts_line: bool,
120 line_number: int | None,
121 label: int | None = None,
122 positions: Positions | None = None,
123 cache_info: list[tuple[str, int, Any]] | None = None,
124 ) -> Instruction: ...
125
126 else:
127 @disjoint_base
128 class Instruction(_Instruction):
129 def _disassemble(self, lineno_width: int = 3, mark_as_current: bool = False, offset_width: int = 4) -> str: ...
130
131 class Bytecode:
132 codeobj: types.CodeType
133 first_line: int
134 if sys.version_info >= (3, 14):
135 show_positions: bool
136 # 3.14 added `show_positions`
137 def __init__(
138 self,
139 x: _HaveCodeType | str,
140 *,
141 first_line: int | None = None,
142 current_offset: int | None = None,
143 show_caches: bool = False,
144 adaptive: bool = False,
145 show_offsets: bool = False,
146 show_positions: bool = False,
147 ) -> None: ...
148 elif sys.version_info >= (3, 13):
149 show_offsets: bool
150 # 3.13 added `show_offsets`
151 def __init__(
152 self,
153 x: _HaveCodeType | str,
154 *,
155 first_line: int | None = None,
156 current_offset: int | None = None,
157 show_caches: bool = False,
158 adaptive: bool = False,
159 show_offsets: bool = False,
160 ) -> None: ...
161 elif sys.version_info >= (3, 11):
162 def __init__(
163 self,
164 x: _HaveCodeType | str,
165 *,
166 first_line: int | None = None,
167 current_offset: int | None = None,
168 show_caches: bool = False,
169 adaptive: bool = False,
170 ) -> None: ...
171 else:
172 def __init__(
173 self, x: _HaveCodeType | str, *, first_line: int | None = None, current_offset: int | None = None
174 ) -> None: ...
175
176 if sys.version_info >= (3, 11):
177 @classmethod
178 def from_traceback(cls, tb: types.TracebackType, *, show_caches: bool = False, adaptive: bool = False) -> Self: ...
179 else:
180 @classmethod
181 def from_traceback(cls, tb: types.TracebackType) -> Self: ...
182
183 def __iter__(self) -> Iterator[Instruction]: ...
184 def info(self) -> str: ...
185 def dis(self) -> str: ...
186
187 COMPILER_FLAG_NAMES: Final[dict[int, str]]
188
189 def findlabels(code: _HaveCodeType) -> list[int]: ...
190 def findlinestarts(code: _HaveCodeType) -> Iterator[tuple[int, int]]: ...
191 def pretty_flags(flags: int) -> str: ...
192 def code_info(x: _HaveCodeType | str) -> str: ...
193
194 if sys.version_info >= (3, 14):
195 # 3.14 added `show_positions`
196 def dis(
197 x: _HaveCodeType | str | bytes | bytearray | None = None,
198 *,
199 file: IO[str] | None = None,
200 depth: int | None = None,
201 show_caches: bool = False,
202 adaptive: bool = False,
203 show_offsets: bool = False,
204 show_positions: bool = False,
205 ) -> None: ...
206 def disassemble(
207 co: _HaveCodeType,
208 lasti: int = -1,
209 *,
210 file: IO[str] | None = None,
211 show_caches: bool = False,
212 adaptive: bool = False,
213 show_offsets: bool = False,
214 show_positions: bool = False,
215 ) -> None: ...
216 def distb(
217 tb: types.TracebackType | None = None,
218 *,
219 file: IO[str] | None = None,
220 show_caches: bool = False,
221 adaptive: bool = False,
222 show_offsets: bool = False,
223 show_positions: bool = False,
224 ) -> None: ...
225
226 elif sys.version_info >= (3, 13):
227 # 3.13 added `show_offsets`
228 def dis(
229 x: _HaveCodeType | str | bytes | bytearray | None = None,
230 *,
231 file: IO[str] | None = None,
232 depth: int | None = None,
233 show_caches: bool = False,
234 adaptive: bool = False,
235 show_offsets: bool = False,
236 ) -> None: ...
237 def disassemble(
238 co: _HaveCodeType,
239 lasti: int = -1,
240 *,
241 file: IO[str] | None = None,
242 show_caches: bool = False,
243 adaptive: bool = False,
244 show_offsets: bool = False,
245 ) -> None: ...
246 def distb(
247 tb: types.TracebackType | None = None,
248 *,
249 file: IO[str] | None = None,
250 show_caches: bool = False,
251 adaptive: bool = False,
252 show_offsets: bool = False,
253 ) -> None: ...
254
255 elif sys.version_info >= (3, 11):
256 # 3.11 added `show_caches` and `adaptive`
257 def dis(
258 x: _HaveCodeType | str | bytes | bytearray | None = None,
259 *,
260 file: IO[str] | None = None,
261 depth: int | None = None,
262 show_caches: bool = False,
263 adaptive: bool = False,
264 ) -> None: ...
265 def disassemble(
266 co: _HaveCodeType, lasti: int = -1, *, file: IO[str] | None = None, show_caches: bool = False, adaptive: bool = False
267 ) -> None: ...
268 def distb(
269 tb: types.TracebackType | None = None, *, file: IO[str] | None = None, show_caches: bool = False, adaptive: bool = False
270 ) -> None: ...
271
272 else:
273 def dis(
274 x: _HaveCodeType | str | bytes | bytearray | None = None, *, file: IO[str] | None = None, depth: int | None = None
275 ) -> None: ...
276 def disassemble(co: _HaveCodeType, lasti: int = -1, *, file: IO[str] | None = None) -> None: ...
277 def distb(tb: types.TracebackType | None = None, *, file: IO[str] | None = None) -> None: ...
278
279 if sys.version_info >= (3, 13):
280 # 3.13 made `show_caches` `None` by default and has no effect
281 @overload
282 def get_instructions(x: _HaveCodeType, *, first_line: int | None = None, adaptive: bool = False) -> Iterator[Instruction]: ...
283 @overload
284 @deprecated(
285 "The `show_caches` parameter is deprecated since Python 3.13. "
286 "The iterator generates the `Instruction` instances with the `cache_info` field populated."
287 )
288 def get_instructions(
289 x: _HaveCodeType, *, first_line: int | None = None, show_caches: bool | None = None, adaptive: bool = False
290 ) -> Iterator[Instruction]: ...
291
292 elif sys.version_info >= (3, 11):
293 def get_instructions(
294 x: _HaveCodeType, *, first_line: int | None = None, show_caches: bool = False, adaptive: bool = False
295 ) -> Iterator[Instruction]: ...
296
297 else:
298 def get_instructions(x: _HaveCodeType, *, first_line: int | None = None) -> Iterator[Instruction]: ...
299
300 def show_code(co: _HaveCodeType, *, file: IO[str] | None = None) -> None: ...
301
302 disco = disassemble