uf.specs#
Function specification management for uf.
Provides a Mapping-based interface to function specifications, including RJSF form specs and OpenAPI schemas.
Functions
|
The docstring of |
|
|
|
The name a function is served under: its |
|
The function a (possibly nested) |
Classes
|
A mapping from function names to their RJSF specifications. |
Exceptions
The form spec of a function could not be generated (the cause is chained). |
|
Emitted when |
|
A callable has no signature to build a form from (e.g. |
|
A callable can never be called from a uf form (e.g. it has a required positional-only parameter). |
- exception uf.specs.FormSpecError[source]#
Bases:
ValueErrorThe form spec of a function could not be generated (the cause is chained).
- class uf.specs.FunctionSpecStore(funcs, *, rjsf_config=None, ui_schema_factory=None, param_to_prop_type=None, validate=False)[source]#
Bases:
MappingA mapping from function names to their RJSF specifications.
Lazily generates and caches form specs for each function.
- Parameters:
funcs (
Union[Iterable[Callable],Mapping[str,Callable]]) – Iterable of callables to generate specs for (named byname_of_func:__name__, the wrapped function’s for afunctools.partial, the class name for a callable instance), or a mapping{name: callable}to name them explicitlyrjsf_config (
Optional[dict]) – Optional configuration dict for RJSF generationui_schema_factory (
Optional[Callable]) – Optional callable to customize UI schema generationparam_to_prop_type (
Optional[Callable]) – Optional callable to map parameters to property typesvalidate (
bool) – If true, every function is checked and its spec generated at construction, so a callable uf can’t build a form for fails there, naming it, rather than on the first request (default false: checked on first access of its spec;mk_rjsf_appvalidates).
Example
>>> def add(x: int, y: int) -> int: ... '''Add two numbers''' ... return x + y >>> specs = FunctionSpecStore([add]) >>> 'add' in specs True >>> spec = specs['add'] >>> 'schema' in spec True
- exception uf.specs.JuNotInstalledWarning[source]#
Bases:
UserWarningEmitted when
juis absent and uf falls back to basic form specs.
- exception uf.specs.UnintrospectableCallableError[source]#
Bases:
ValueErrorA callable has no signature to build a form from (e.g.
max,getattr).
- exception uf.specs.UnservableCallableError[source]#
Bases:
ValueErrorA callable can never be called from a uf form (e.g. it has a required positional-only parameter).
- uf.specs.doc_of_func(func)[source]#
The docstring of
func; for afunctools.partial(whose own__doc__is the generic one ofpartial), that of the function it wraps.>>> import functools >>> def f(x, y): ... "Add." >>> doc_of_func(functools.partial(f, y=1)) 'Add.'
- uf.specs.name_funcs(funcs)[source]#
{name: callable}from a mapping of explicit names, or an iterable of callables (named byname_of_func). Two different callables sharing a name raise.- Return type:
>>> import functools >>> name_funcs([len, functools.partial(int, base=2)]) {'len': <built-in function len>, 'int': functools.partial(<class 'int'>, base=2)} >>> name_funcs({'size': len}) {'size': <built-in function len>}
- uf.specs.name_of_func(func)[source]#
The name a function is served under: its
__name__; failing that, for afunctools.partial, that of the function it wraps; for a callable instance, its class name.- Return type:
>>> import functools >>> name_of_func(len) 'len' >>> name_of_func(functools.partial(int, base=2)) 'int' >>> class Doubler: ... def __call__(self, x): return 2 * x >>> name_of_func(Doubler()) 'Doubler'