argclz.dispatch.annotations.validator_for#

argclz.dispatch.annotations.validator_for(arg: str) Callable[[F], F][source]#
argclz.dispatch.annotations.validator_for(arg: str, caster: Callable[[str], T] | Validator) Callable[[F], F]
argclz.dispatch.annotations.validator_for(arg: str, caster: Callable[[str], T], validator: Validator) Callable[[F], F]

A decorator that do the caster and valudation on dispatch arguments.

Example

>>> class D(Dispatch):
...     @dispatch('cmd')
...     @validator_for('a')
...     def run_cmd(self, a: int):
...         assert isinstance(a, int)

Type (caster)

The parameter caster usually can be infered via the annotation of target parameter, like the a: int in above example.

Parameters:
  • arg – name of the parameter.

  • caster – type caster with the signature (str) -> T.

  • validator – validator with the signatire (T) -> bool.