MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _get_code_object

Function _get_code_object

tools/python-3.11.9-amd64/Lib/dis.py:160–181  ·  view source on GitHub ↗

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

(x)

Source from the content-addressed store, hash-verified

158UNKNOWN = _Unknown()
159
160def _get_code_object(x):
161 """Helper to handle methods, compiled or raw code objects, and strings."""
162 # Extract functions from methods.
163 if hasattr(x, '__func__'):
164 x = x.__func__
165 # Extract compiled code objects from...
166 if hasattr(x, '__code__'): # ...a function, or
167 x = x.__code__
168 elif hasattr(x, 'gi_code'): #...a generator object, or
169 x = x.gi_code
170 elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or
171 x = x.ag_code
172 elif hasattr(x, 'cr_code'): #...a coroutine.
173 x = x.cr_code
174 # Handle source code.
175 if isinstance(x, str):
176 x = _try_compile(x, "<disassembly>")
177 # By now, if we don't have a code object, we can't disassemble x.
178 if hasattr(x, 'co_code'):
179 return x
180 raise TypeError("don't know how to disassemble %s objects" %
181 type(x).__name__)
182
183def _deoptop(op):
184 name = _all_opname[op]

Callers 3

code_infoFunction · 0.85
get_instructionsFunction · 0.85
__init__Method · 0.85

Calls 2

_try_compileFunction · 0.85
typeClass · 0.50

Tested by

no test coverage detected