Detail: CallGuard: Method

Overview: CallGuard: Method

static CallGuard.check(func=None, /, *, fail_fast=False)[source]

A function decorator to perform run-time checking of function arguments and return values based on the function type annotations, including type hints and Require-provided validators. Raises ClinicError on failure.

>>> def func1(ix: sf.Index[np.int64]): return len(ix)
>>> func2 = sf.CallGuard.check(func1)
>>> func2
<function func1 at 0x7f656330eb60>
>>> ix1 = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> func2(ix1)
ClinicError('\nIn args of (ix: Index[int64]) -> Any\n└── Index[int64]\n    └── Expected int64, provided str_ invalid')
>>> ix2 = sf.Index((1024, 2048, 4096), name='y')
>>> func2(ix2)
3
>>> import typing as tp
>>> def func3(ix: tp.Annotated[sf.Index[np.int64], sf.Require.Len(4)]): return len(ix)
>>> func4 = sf.CallGuard.check(func3)
>>> func4(ix1)
ClinicError('\nIn args of (ix: Annotated[Index[int64], Len(4)]) -> Any\n└── Annotated[Index[int64], Len(4)]\n    └── Len(4)\n        └── Expected length 4, provided length 5\nIn args of (ix: Annotated[Index[int64], Len(4)]) -> Any\n└── Annotated[Index[int64], Len(4)]\n    └── Index[int64]\n        └── Expected int64, provided str_ invalid')
>>> func4(ix2)
ClinicError('\nIn args of (ix: Annotated[Index[int64], Len(4)]) -> Any\n└── Annotated[Index[int64], Len(4)]\n    └── Len(4)\n        └── Expected length 4, provided length 3')
>>> ix3 = sf.Index((0, 1024, -2048, 4096))
>>> func4(ix3)
4
static CallGuard.warn(func=None, /, *, fail_fast=False, category=<class 'UserWarning'>)[source]

A function decorator to perform run-time checking of function arguments and return values based on the function type annotations, including type hints and Require-provided validators. Issues a warning on failure.

CallGuard: Method