Format: application/octet-stream
1 import sys
2 import types
3 from opcode import (
4 EXTENDED_ARG as EXTENDED_ARG,
5 HAVE_ARGUMENT as HAVE_ARGUMENT,
6 cmp_op as cmp_op,
7 hascompare as hascompare,
8 hasconst as hasconst,
9 hasfree as hasfree,
10 hasjabs as hasjabs,
11 hasjrel as hasjrel,
12 haslocal as haslocal,
13 hasname as hasname,
14 opmap as opmap,
15 opname as opname,
16 )
17 from typing import IO, Any, Callable, Dict, Iterator, List, NamedTuple, Optional, Tuple, Union
18
19 if sys.version_info >= (3, 4):
20 from opcode import stack_effect as stack_effect
21
22 if sys.version_info >= (3, 6):
23 from opcode import hasnargs as hasnargs
24
25 # Strictly this should not have to include Callable, but mypy doesn't use FunctionType
26 # for functions (python/mypy#3171)
27 _have_code = Union[types.MethodType, types.FunctionType, types.CodeType, type, Callable[..., Any]]
28 _have_code_or_string = Union[_have_code, str, bytes]
29
30 if sys.version_info >= (3, 4):
31 class Instruction(NamedTuple):
32 opname: str
33 opcode: int
34 arg: Optional[int]
35 argval: Any
36 argrepr: str
37 offset: int
38 starts_line: Optional[int]
39 is_jump_target: bool
40 class Bytecode:
41 codeobj: types.CodeType
42 first_line: int
43 def __init__(
44 self, x: _have_code_or_string, *, first_line: Optional[int] = ..., current_offset: Optional[int] = ...
45 ) -> None: ...
46 def __iter__(self) -> Iterator[Instruction]: ...
47 def __repr__(self) -> str: ...
48 def info(self) -> str: ...
49 def dis(self) -> str: ...
50 @classmethod
51 def from_traceback(cls, tb: types.TracebackType) -> Bytecode: ...
52
53 COMPILER_FLAG_NAMES: Dict[int, str]
54
55 def findlabels(code: _have_code) -> List[int]: ...
56 def findlinestarts(code: _have_code) -> Iterator[Tuple[int, int]]: ...
57
58 if sys.version_info >= (3, 0):
59 def pretty_flags(flags: int) -> str: ...
60 def code_info(x: _have_code_or_string) -> str: ...
61
62 if sys.version_info >= (3, 7):
63 def dis(x: Optional[_have_code_or_string] = ..., *, file: Optional[IO[str]] = ..., depth: Optional[int] = ...) -> None: ...
64
65 elif sys.version_info >= (3, 4):
66 def dis(x: Optional[_have_code_or_string] = ..., *, file: Optional[IO[str]] = ...) -> None: ...
67
68 else:
69 def dis(x: _have_code_or_string = ...) -> None: ...
70
71 if sys.version_info >= (3, 4):
72 def distb(tb: Optional[types.TracebackType] = ..., *, file: Optional[IO[str]] = ...) -> None: ...
73 def disassemble(co: _have_code, lasti: int = ..., *, file: Optional[IO[str]] = ...) -> None: ...
74 def disco(co: _have_code, lasti: int = ..., *, file: Optional[IO[str]] = ...) -> None: ...
75 def show_code(co: _have_code, *, file: Optional[IO[str]] = ...) -> None: ...
76 def get_instructions(x: _have_code, *, first_line: Optional[int] = ...) -> Iterator[Instruction]: ...
77
78 else:
79 def distb(tb: types.TracebackType = ...) -> None: ...
80 def disassemble(co: _have_code, lasti: int = ...) -> None: ...
81 def disco(co: _have_code, lasti: int = ...) -> None: ...
82 if sys.version_info >= (3, 0):
83 def show_code(co: _have_code) -> None: ...
84