Factory¶
Sorry, the person who is responsible for the description was eaten by hydras last week.
- hydra_slayer.factory.call_meta_factory(factory: Union[Type, Callable[[...], Any]], args: Tuple, kwargs: Mapping)[source]¶
Creates a new instance from
factory
.- Parameters
factory – factory to create instance from
args – *args to pass to the factory
kwargs – **kwargs to pass to the factory
- Returns
Instance.
- hydra_slayer.factory.default_meta_factory(factory: Union[Type, Callable[[...], Any]], args: Tuple, kwargs: Mapping)[source]¶
Returns a new instance or a new partial object.
_mode_=’auto’
Creates a new instance from
factory
iffactory
is class (likecall_meta_factory()
), else returns a new partial object (likepartial_meta_factory()
)._mode_=’call’
Returns a result of the factory called with the positional arguments
args
and keyword argumentskwargs
._mode_=’partial’
Returns a new partial object which when called will behave like factory called with the positional arguments
args
and keyword argumentskwargs
.
- Parameters
factory – factory to create instance from
args – *args to pass to the factory
kwargs – **kwargs to pass to the factory
- Returns
Instance.
- Raises
ValueError – if mode not in list:
'auto'
,'call'
,'partial'
.
Examples
>>> default_meta_factory(int, (42,)) 42
>>> # please note that additional () are used >>> default_meta_factory(lambda x: x, (42,))() 42
>>> default_meta_factory(int, ('42',), {"base": 16}) 66
>>> # please note that additional () are not needed >>> default_meta_factory(lambda x: x, (42,), {"_mode_": "call"}) 42
>>> default_meta_factory(lambda x: x, ('42',), {"_mode_": "partial", "base": 16})() 66
- hydra_slayer.factory.partial_meta_factory(factory: Union[Type, Callable[[...], Any]], args: Tuple, kwargs: Mapping)[source]¶
Returns a new partial object which when called will behave like func called with the positional arguments
args
and keyword argumentskwargs
.- Parameters
factory – factory to create instance from
args – *args to merge into the factory
kwargs – **kwargs to merge into the factory
- Returns
Partial object.