magicclass.functools package¶
Module contents¶
A magic-class submodule that mimics the built-in functools
module.
- class magicclass.functools.partial(func, /, *args, **kwargs)[source]¶
Bases:
functools.partial
Partialize a function and its signature.
This object is similar to
functools.partial
, but it also update widget options to build magicgui widget with subset of widgets. More precisely, partializingx=0
will add optionx={"gui_only": True, "widget_type": EmptyWidget, "visible": False}
.- Parameters
func (Callable) -- Callable object to be partialized.
Examples
Suppose you have a magic class.
>>> @magicclass >>> class A: >>> def f(self, i: int): ...
You can partialize method
f
.>>> ui = A() >>> ui.append(partial(ui.f, i=1))
- class magicclass.functools.partialmethod(func, /, *args, **kwargs)[source]¶
Bases:
functools.partialmethod
Partialize a method and its signature.
This object is similar to
functools.partialmethod
, but it also update widget options to build magicgui widget with subset of widgets. More precisely, partializingx=0
will add optionx={"gui_only": True, "widget_type": EmptyWidget, "visible": False}
.- Parameters
func (Callable) -- Callable object to be partialized.
Examples
>>> @magicclass >>> class A: >>> def f(self, i: int): ... >>> g = partialmethod(f, i=1)
- magicclass.functools.singledispatch(func)[source]¶
Single dispatch function aware of GUI options in magic-class.
Dispatched functions are converted into a multi-valued widget. GUI configurations are also possible using
@set_options
decorator.
- class magicclass.functools.singledispatchmethod(func)[source]¶
Bases:
functools.singledispatchmethod
Single dispatch method aware of GUI options in magic-class.
Dispatched functions are converted into a multi-valued widget. GUI configurations are also possible using
@set_options
decorator.
- magicclass.functools.wraps(template: Callable | inspect.Signature) Callable[[_C], _C] [source]¶
Update signature using a template. If class is wrapped, then all the methods except for those start with "__" will be wrapped.
- Parameters
template (Callable or inspect.Signature object) -- Template function or its signature.
- Returns
A wrapper which take a function or class as an input and returns same function or class with updated signature(s).
- Return type
Callable