neuralib.util.func.create_fn
- neuralib.util.func.create_fn(name, sign, body='pass', *, globals=None, locals=None)[source]
Example:
>>> add = create_fn('add', (['a', 'b'], int), 'return a + b') >>> add(1, 2) 3 >>> def add_sign(a: int, b:int) -> int: ... pass >>> add = create_fn('add', add_sign, 'return a + b') >>> add(1, 2) 3
Signature Example
>>> def f(a, b:int, c=0, d:int=1) -> int: (['a', ('b', int), ('c', None, '0'), ('d', int, '1')], int)
reference: dataclasses._create_fn
- Parameters:
name (str)
sign (list[str | tuple[str, str | type] | tuple[str, None | str | type, str]] | tuple[list[str | tuple[str, str | type] | tuple[str, None | str | type, str]], None | str | type] | Callable[[...], Any]) – ([arg_name|(arg_name, arg_type)|(arg_name, arg_type?, str(default)),…], ret_type)
body (str)
globals (dict[str, Any] | None)
locals (dict[str, Any] | None)
- Returns:
- Return type:
Callable[[…], Any]