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) – ([arg_name|(arg_name, arg_type)|(arg_name, arg_type?, str(default)),…], ret_type)
body (str)
globals
locals (dict[str, Any])
- Returns:
- Return type:
Callable[[…], T]