finprint.stepcode
module finprint
What a named step’s code needs besides its arguments, checked when the step runs.
Replay execs a named step’s recorded source in a fresh namespace, so every global name the function reads must
be recorded too, or the step cannot replay. step_globals reads the function’s bytecode (LOAD_GLOBAL,
LOAD_NAME and closure cells, nested functions and comprehensions included) and sorts each name:
- modules replay imports (
pd,np,math,re…) are recorded as{"__module__": name}; - functions on the replay allowlist (
from math import log) are recorded as{"__callable__": ...}; - JSON-safe constants (
AGENCY_FEE = 0.15) are recorded by value, under the same privacy rules as arguments; - anything else makes the step not replayable, with the reason: another module or helper whose code is not in the
recipe, a DataFrame the step reads without taking it as an argument (its rows and lineage would be missing), a
name that is not defined, or file I/O inside the step (
pd.read_csv,open,to_csv).
Functions
Section titled “Functions”step_globals
Section titled “step_globals”function
def step_globals(f: Callable[..., Any]) -> tuple[dict[str, Any], list[str]]The global names f reads, encoded for replay, and the reasons it cannot replay (empty when it can).
Source: packages/finprint/src/finprint/stepcode.py, line 64
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
IO_ATTRS | frozenset({'read_csv', 'read_excel', 'read_parquet', 'read_json', 'read_pickl... | ||
UNSAFE_BUILTINS | frozenset({'open', 'exec', 'eval', 'compile', '__import__', 'input', 'breakpo... |