executing
This mini-package lets you get information about what a frame is currently doing, particularly the AST node being executed.
Usage
Getting the AST node
Getting the source code of the node
Getting the __qualname__ of the current function
The Source class
Installation
How does it work?
Is it reliable?
Which nodes can it identify?
Libraries that use this
Usage
Getting the AST node
import executing
node = executing.Source.executing(frame).node
Then node will be an AST node (from the ast standard library module) or None if the node couldn't be identified (which may happen often and should always be checked).
node will always be the same instance for multiple calls with frames at the same point of execution.
If you have a traceback object, pass it directly to Source.executing() rather than the tb_frame attribute to get the correct node.
Getting the source code of the node
For this you will need to separately install the asttokens library, then obtain an ASTTokens object:
e
|