"""Type annotations validator using :mod:`beartype`."""frombeartype.valeimportIsfrombeartype.vale._core._valecoreimportBeartypeValidator
[docs]defnot_empty()->BeartypeValidator:"""Makes sure the string is not empty. Returns: A :mod:`beartype` object that raises an exception if the annotated value does not satisfy the condition. """def_not_empty(x:object)->bool:returnisinstance(x,str)andlen(x)>0returnIs[lambdax:_not_empty(x)]
[docs]defequal(element:object)->BeartypeValidator:"""Verifies that the annotated value is equal to the input argument. Args: element: The object to compare the annotated value against. Returns: See return description of :func:`not_empty`. """def_equal(x:object,element:object)->bool:returnx==elementreturnIs[lambdax:_equal(x,element)]
[docs]defone_of(*elements:object)->BeartypeValidator:"""Verifies that the annotated value is one of the input arguments. Used to replace :class:`typing.Literal` which is not supported by :mod:`omegaconf`-based configs. Args: elements: The objects to compare the annotated value against. Returns: See return description of :func:`not_empty`. """def_one_of(x:object,elements:tuple[object,...])->bool:returnxinelementsreturnIs[lambdax:_one_of(x,elements)]
[docs]defge(val:float)->BeartypeValidator:"""Verifies that the annotated value is ``> or =`` :paramref:`val`. Args: val: The value to compare the annotated value against. Returns: See return description of :func:`not_empty`. """def_ge(x:object,val:float)->bool:returnisinstance(x,int|float)andx>=valreturnIs[lambdax:_ge(x,val)]
[docs]defgt(val:float)->BeartypeValidator:"""Verifies that the annotated value is ``>`` :paramref:`val`. Args: val: See :paramref:`~ge.val`. Returns: See return description of :func:`not_empty`. """def_gt(x:object,val:float)->bool:returnisinstance(x,int|float)andx>valreturnIs[lambdax:_gt(x,val)]
[docs]defle(val:float)->BeartypeValidator:"""Verifies that the annotated value is ``< or =`` :paramref:`val`. Args: val: See :paramref:`~ge.val`. Returns: See return description of :func:`not_empty`. """def_le(x:object,val:float)->bool:returnisinstance(x,int|float)andx<=valreturnIs[lambdax:_le(x,val)]
[docs]deflt(val:float)->BeartypeValidator:"""Verifies that the annotated value is ``<`` :paramref:`val`. Args: val: See :paramref:`~ge.val`. Returns: See return description of :func:`not_empty`. """def_lt(x:object,val:float)->bool:returnisinstance(x,int|float)andx<valreturnIs[lambdax:_lt(x,val)]