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

Function _get_code_object

Lib/dis.py:191–212  ·  view source on GitHub ↗

Helper to handle methods, compiled or raw code objects, and strings.

(x)

Source from the content-addressed store, hash-verified

189UNKNOWN = _Unknown()
190
191def _get_code_object(x):
192 """Helper to handle methods, compiled or raw code objects, and strings."""
193 # Extract functions from methods.
194 if hasattr(x, '__func__'):
195 x = x.__func__
196 # Extract compiled code objects from...
197 if hasattr(x, '__code__'): # ...a function, or
198 x = x.__code__
199 elif hasattr(x, 'gi_code'): #...a generator object, or
200 x = x.gi_code
201 elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or
202 x = x.ag_code
203 elif hasattr(x, 'cr_code'): #...a coroutine.
204 x = x.cr_code
205 # Handle source code.
206 if isinstance(x, str):
207 x = _try_compile(x, "<disassembly>")
208 # By now, if we don't have a code object, we can't disassemble x.
209 if hasattr(x, 'co_code'):
210 return x
211 raise TypeError("don't know how to disassemble %s objects" %
212 type(x).__name__)
213
214def _deoptop(op):
215 name = _all_opname[op]

Callers 3

code_infoFunction · 0.85
get_instructionsFunction · 0.85
__init__Method · 0.85

Calls 3

hasattrFunction · 0.85
isinstanceFunction · 0.85
_try_compileFunction · 0.85

Tested by

no test coverage detected