Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.05 KB

function.md

File metadata and controls

48 lines (36 loc) · 1.05 KB

FunctionContext

The FunctionContext captures the arguments of a function. It can be created using the capsula.FunctionContext.builder method or the capsula.FunctionContext.__init__ method.

::: capsula.FunctionContext.builder ::: capsula.FunctionContext.init

Configuration example

Via capsula.toml

!!! warning Configuring the FunctionContext via capsula.toml is not recommended because capsula enc will fail as there is no target function to capture.

[pre-run]
contexts = [
  { type = "FunctionContext" },
]

Via @capsula.context decorator

import capsula

@capsula.run()
@capsula.context(capsula.FunctionContext.builder(), mode="pre")
def func(arg1, arg2): ...

Output example

The following is an example of the output of the FunctionContext, reported by the JsonDumpReporter:

"function": {
  "calculate_pi": {
    "file_path": "examples/simple_decorator.py",
    "first_line_no": 6,
    "bound_args": {
      "n_samples": 1000,
      "seed": 42
    }
  }
}