Module osbot_utils.helpers.trace.Trace_Call__Stack_Node
Expand source code
from osbot_utils.utils.Misc import random_id
from osbot_utils.utils.Dev import pprint
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
EXTRA_DATA__RETURN_VALUE = '(return_value)'
class Trace_Call__Stack_Node(Kwargs_To_Self):
call_duration : float
call_end : float
call_index : int
call_start : float
children : list
extra_data : dict
locals : dict
frame : None
func_name : str
lines : list
key : str
module : str
name : str
source_code : str
source_code_caller : str
source_code_location: str
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# #self.key = random_id()
def __eq__(self, other):
if not isinstance(other, Trace_Call__Stack_Node):
return False
if self is other:
return True
return self.data() == other.data()
def __repr__(self):
return f'Trace_Call__Stack_Node (call_index={self.call_index})'
def all_children(self):
all_children = self.children.copy() # Initialize the list with the current node's children
for child in self.children: # Recursively add the children of each child node
all_children.extend(child.all_children())
return all_children
def info(self):
return f'Stack_Node: call_index:{self.call_index} | name: {self.name} | children: {len(self.children)} | source_code: {self.source_code is not None}'
def data(self):
return self.__locals__()
def print(self):
pprint(self.data())
def print_info(self):
pprint(self.info())
Classes
class Trace_Call__Stack_Node (**kwargs)
-
A mixin class to strictly assign keyword arguments to pre-defined instance attributes during initialization.
This base class provides an init method that assigns values from keyword arguments to instance attributes. If an attribute with the same name as a key from the kwargs is defined in the class, it will be set to the value from kwargs. If the key does not match any predefined attribute names, an exception is raised.
This behavior enforces strict control over the attributes of instances, ensuring that only predefined attributes can be set at the time of instantiation and avoids silent attribute creation which can lead to bugs in the code.
Usage
class MyConfigurableClass(Kwargs_To_Self): attribute1 = 'default_value' attribute2 = True attribute3 : str attribute4 : list attribute4 : int = 42
# Other methods can be added here
Correctly override default values by passing keyword arguments
instance = MyConfigurableClass(attribute1='new_value', attribute2=False)
This will raise an exception as 'attribute3' is not predefined
instance = MyConfigurableClass(attribute3='invalid_attribute')
this will also assign the default value to any variable that has a type defined. In the example above the default values (mapped by default__kwargs and locals) will be: attribute1 = 'default_value' attribute2 = True attribute3 = '' # default value of str attribute4 = [] # default value of list attribute4 = 42 # defined value in the class
Note
It is important that all attributes which may be set at instantiation are predefined in the class. Failure to do so will result in an exception being raised.
Methods
init(**kwargs): The initializer that handles the assignment of keyword arguments to instance attributes. It enforces strict attribute assignment rules, only allowing attributes that are already defined in the class to be set.
Initialize an instance of the derived class, strictly assigning provided keyword arguments to corresponding instance attributes.
Parameters
**kwargs: Variable length keyword arguments.
Raises
Exception
- If a key from kwargs does not correspond to any attribute pre-defined in the class, an exception is raised to prevent setting an undefined attribute.
Expand source code
class Trace_Call__Stack_Node(Kwargs_To_Self): call_duration : float call_end : float call_index : int call_start : float children : list extra_data : dict locals : dict frame : None func_name : str lines : list key : str module : str name : str source_code : str source_code_caller : str source_code_location: str # def __init__(self, **kwargs): # super().__init__(**kwargs) # #self.key = random_id() def __eq__(self, other): if not isinstance(other, Trace_Call__Stack_Node): return False if self is other: return True return self.data() == other.data() def __repr__(self): return f'Trace_Call__Stack_Node (call_index={self.call_index})' def all_children(self): all_children = self.children.copy() # Initialize the list with the current node's children for child in self.children: # Recursively add the children of each child node all_children.extend(child.all_children()) return all_children def info(self): return f'Stack_Node: call_index:{self.call_index} | name: {self.name} | children: {len(self.children)} | source_code: {self.source_code is not None}' def data(self): return self.__locals__() def print(self): pprint(self.data()) def print_info(self): pprint(self.info())
Ancestors
Class variables
var call_duration : float
var call_end : float
var call_index : int
var call_start : float
var children : list
var extra_data : dict
var frame : None
var func_name : str
var key : str
var lines : list
var locals : dict
var module : str
var name : str
var source_code : str
var source_code_caller : str
var source_code_location : str
Methods
def all_children(self)
-
Expand source code
def all_children(self): all_children = self.children.copy() # Initialize the list with the current node's children for child in self.children: # Recursively add the children of each child node all_children.extend(child.all_children()) return all_children
def data(self)
-
Expand source code
def data(self): return self.__locals__()
def info(self)
-
Expand source code
def info(self): return f'Stack_Node: call_index:{self.call_index} | name: {self.name} | children: {len(self.children)} | source_code: {self.source_code is not None}'
def print(self)
-
Expand source code
def print(self): pprint(self.data())
def print_info(self)
-
Expand source code
def print_info(self): pprint(self.info())
Inherited members