Tracer¶
- torii.util.tracer.get_src_loc(src_loc_at: int = 0) tuple[str, int] ¶
Get the file and line number from the given frame on the call stack.
By default, the result will be the file and line number from the call frame directly above the on in which
get_src_loc
is called.This means, that if
get_src_loc
is called in the constructor of an object, then the location information returned will be of where that constructor was called.- Parameters:
src_loc_at (int) – The frame above this call in which to get the file and line number from.
Example
>>> class Nya: ... def __init__(self) -> None: ... self.src = get_src_loc() ... >>> meow = Nya() # `meow.src` will be this line >>> meow.src ('<python-input-4>', 1)
- torii.util.tracer.get_var_name(depth: int = 2, default: str | object = <object object>) str ¶
Get the variable name from an assignment up the call stack.
By default, the result will be the file and line number from the call frame directly above the on in which
get_var_name
is called.This means, that if
get_var_name
is called in the constructor of an object, then the return value will be the name of the assignment that was done when constructing the object.Example
>>> class Nya: ... def __init__(self) -> None: ... self.name = get_var_name() ... >>> meow = Nya() # `meow.name` will be `meow` >>> meow.name 'meow'
- Parameters:
- Return type:
Important
The default value of
depth
is set so that the assignment of the result of the current call frame will be used.- Raises:
NameNotFound – When the value of
default
is not explicitly set and we are unable to determine the name.