MCPcopy Index your code
hub / github.com/python/cpython / _get_code_object

Function _get_code_object

Lib/dis.py:192–213  ·  view source on GitHub ↗

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

(x)

Source from the content-addressed store, hash-verified

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

Callers 3

code_infoFunction · 0.85
get_instructionsFunction · 0.85
__init__Method · 0.85

Calls 1

_try_compileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…