xdev.introspect module¶
- xdev.introspect.get_stack_frame(N=0, strict=True)[source]¶
- Parameters:
N (int) – N=0 means the frame you called this function in. N=1 is the parent frame.
strict (bool) – (default = True)
- xdev.introspect.distext(obj)[source]¶
Like dis.dis, but returns the text
- Parameters:
obj – a compiled object (e.g. a function, class, generator, etc…)
- Returns:
text of the python byte code
- Return type:
Example
>>> from xdev.introspect import * # NOQA >>> import ubelt as ub >>> code = ub.codeblock( ''' def foo(a, b): print('hello') if __debug__: if a is None or b is None: raise ValueError print('world') # This is not entirely optimized away if __debug__ and (a is None or b is None): raise ValueError return a + b ''') >>> obj = compile(code, filename='<memory>', mode='exec', dont_inherit=True, optimize=0) >>> print(' ** UNOPTIMIZED') >>> text = distext(obj) >>> print(text) >>> print(' ** OPTIMIZED') >>> obj = compile(code, filename='<memory>', mode='exec', dont_inherit=True, optimize=1) >>> text = distext(obj) >>> print(text)