MCPcopy Index your code
hub / github.com/RustPython/RustPython / dis

Function dis

Lib/dis.py:85–137  ·  view source on GitHub ↗

Disassemble classes, methods, functions, and other compiled objects. With no argument, disassemble the last traceback. Compiled objects currently include generator objects, async generator objects, and coroutine objects, all of which store their code object in a special attribute.

(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
        show_offsets=False, show_positions=False)

Source from the content-addressed store, hash-verified

83 return compile(source, name, 'exec')
84
85def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
86 show_offsets=False, show_positions=False):
87 """Disassemble classes, methods, functions, and other compiled objects.
88
89 With no argument, disassemble the last traceback.
90
91 Compiled objects currently include generator objects, async generator
92 objects, and coroutine objects, all of which store their code object
93 in a special attribute.
94 """
95 if x is None:
96 distb(file=file, show_caches=show_caches, adaptive=adaptive,
97 show_offsets=show_offsets, show_positions=show_positions)
98 return
99 # Extract functions from methods.
100 if hasattr(x, '__func__'):
101 x = x.__func__
102 # Extract compiled code objects from...
103 if hasattr(x, '__code__'): # ...a function, or
104 x = x.__code__
105 elif hasattr(x, 'gi_code'): #...a generator object, or
106 x = x.gi_code
107 elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or
108 x = x.ag_code
109 elif hasattr(x, 'cr_code'): #...a coroutine.
110 x = x.cr_code
111 # Perform the disassembly.
112 if hasattr(x, '__dict__'): # Class or module
113 items = sorted(x.__dict__.items())
114 for name, x1 in items:
115 if isinstance(x1, _have_code):
116 print("Disassembly of %s:" % name, file=file)
117 try:
118 dis(x1, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive, show_offsets=show_offsets, show_positions=show_positions)
119 except TypeError as msg:
120 print("Sorry:", msg, file=file)
121 print(file=file)
122 elif hasattr(x, 'co_code'): # Code object
123 _disassemble_recursive(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive, show_offsets=show_offsets, show_positions=show_positions)
124 elif isinstance(x, (bytes, bytearray)): # Raw bytecode
125 labels_map = _make_labels_map(x)
126 label_width = 4 + len(str(len(labels_map)))
127 formatter = Formatter(file=file,
128 offset_width=len(str(max(len(x) - 2, 9999))) if show_offsets else 0,
129 label_width=label_width,
130 show_caches=show_caches)
131 arg_resolver = ArgResolver(labels_map=labels_map)
132 _disassemble_bytes(x, arg_resolver=arg_resolver, formatter=formatter)
133 elif isinstance(x, str): # Source code
134 _disassemble_str(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive, show_offsets=show_offsets, show_positions=show_positions)
135 else:
136 raise TypeError("don't know how to disassemble %s objects" %
137 type(x).__name__)
138
139def distb(tb=None, *, file=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False):
140 """Disassemble a traceback (default: last traceback)."""

Callers 1

mainFunction · 0.70

Calls 15

distbFunction · 0.85
hasattrFunction · 0.85
sortedFunction · 0.85
isinstanceFunction · 0.85
_disassemble_recursiveFunction · 0.85
_make_labels_mapFunction · 0.85
lenFunction · 0.85
strFunction · 0.85
maxFunction · 0.85
ArgResolverClass · 0.85
_disassemble_bytesFunction · 0.85
_disassemble_strFunction · 0.85

Tested by

no test coverage detected