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.
Examples
>>> call_meta_factory(int, (42,), {}) 42 >>> call_meta_factory(int, ('2A',), {'base': 16}) 66 >>> call_meta_factory(lambda x: x, (42,), {}) 42
- 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.
Creates a new instance from
factory
iffactory
is class (behaves likecall_meta_factory()
), else returns a new partial object (behaves likepartial_meta_factory()
).- 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 factory object is not callable.
Examples
>>> default_meta_factory(int, (42,), {}) 42 >>> default_meta_factory(int, ('2A',), {'base': 16}) 42 >>> get_answer_to_life = default_meta_factory(lambda x: x, (42,), {}) >>> get_answer_to_life() 42
- hydra_slayer.factory.metafactory_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
>>> metafactory_factory(int, (42,)) 42 >>> metafactory_factory(lambda x: x, (42,))() # note that additional () are used 42 >>> metafactory_factory(lambda x: x, (42,), {'_mode_': 'call'}) 42 >>> metafactory_factory(int, ('2A'), {'base': 16}) 42 >>> hex_to_dec = metafactory_factory(int, (), {'_mode_': 'partial', 'base': 16}) >>> hex_to_dec('2A') 42
- 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.
Examples
>>> get_answer_to_life = partial_meta_factory(lambda x: x, (42,), {}) >>> get_answer_to_life() 42 >>> hex_to_dec = partial_meta_factory(int, (), {'base': 16}) >>> hex_to_dec('2A') 42