pyquibbler.quiby
- pyquibbler.quiby(func: Callable | None = None, lazy: bool | None = None, pass_quibs: bool = False, is_random: bool = False, is_graphics: bool | None = False, is_file_loading: bool = False, quibify_even_if_quibbler_not_initialized: bool = False, **kwargs) Callable[[...], Quib]
Convert a regular function into a quiby function.
Converts any function func to a function that can work on quib arguments (“quiby” function). When such quiby function is called, it creates a function quib that implement the original function.
quiby can also be used as a decorator of user functions, either directly, or as a function with parameter specification (see examples).
- Parameters:
func (Callable) – The function to convert.
lazy (bool or None, default None) – Indicates whether the created function quib evaluates immediately (lazy=False), or only when its value is requested (lazy=True). When lazy=None (default), the function is evaluated immediately only if it is a declared graphics function (is_graphics=True).
pass_quibs (bool, default False) – Indicates whether the function should be called with quib arguments (pass_quibs=True), or with the values of the quib arguments (pass_quibs=False, default).
is_random (bool, default False) – Indicates a random function. Random functions are automatically cached and can be invalidated centrally to re-randomize (see reset_random_quibs).
is_graphics (bool or None, default: False) – Specifies whether the function creates graphics. If True, the function will be re-evaluated upon any upstream quib changes (according to the quib’s graphics_update property), and any graphics it creates will be redrawn. is_graphics=None will search for graphics during the call to the function and the quib will automatically be defined as a graphics quib if any graphics was created.
is_file_loading (bool, default: False) – Indicates whether the function’s returned value depends on reading of an external file. File-loading functions can be invalidated centrally to re-load (see reset_file_loading_quibs).
- Returns:
a quiby function, or a quiby decorator (if function is not specified)
- Return type:
Callable
See also
is_quiby
,q
,Quib.graphics_update
,Quib.is_graphics
,Quib.is_random
,Quib.is_file_loading
,reset_random_quibs
,reset_file_loading_quibs
Examples
>>> a = iquib(2) >>> b = quiby(str)(a) >>> b.get_value() '2'
>>> @quiby ... def display_variable(name: str, x:int): ... return f'{name} = {x}' ... >>> num = iquib(7) >>> display_num = display_variable('num', num) >>> display_num.get_value() 'x = 7'
>>> @quiby(is_random=True) ... def sum_of_dice(n: int): ... dice = np.random.randint(1, 6, n) ... return np.sum(dice) ... >>> n = iquib(2) >>> sum_dice = sum_of_dice(n) >>> sum_dice.get_value() 17 >>> reset_random_quibs() >>> sum_dice.get_value() 27
Note
If Quibbler has not been initialized, quiby will simply return the unmodified function, not a quiby function. This allows checking how your code works without quibs.