"""Functions that create new predicates that succeed when their argument is strictly or nonstrictly between the upper and lower bounds. There are corresponding phantom types thatuse these predicates in :py:mod:`phantom.interval`."""fromtypingimportTypeVarfromphantom._utils.typesimportSupportsLeGefromphantom._utils.typesimportSupportsLeGtfromphantom._utils.typesimportSupportsLtGefromphantom._utils.typesimportSupportsLtGtfrom._baseimportPredicatefrom._utilsimportbind_nameT=TypeVar("T")
[docs]defexclusive(low:T,high:T)->Predicate[SupportsLtGt[T]]:""" Create a predicate that succeeds when its argument is in the range ``(low, high)``. """@bind_name(exclusive,low,high)defcheck(value:SupportsLtGt[T])->bool:returnlow<value<highreturncheck
[docs]defexclusive_inclusive(low:T,high:T)->Predicate[SupportsLeGt[T]]:""" Create a predicate that succeeds when its argument is in the range ``(low, high]``. """@bind_name(exclusive_inclusive,low,high)defcheck(value:SupportsLeGt[T])->bool:returnlow<value<=highreturncheck
[docs]definclusive_exclusive(low:T,high:T)->Predicate[SupportsLtGe[T]]:""" Create a predicate that succeeds when its argument is in the range ``[low, high)``. """@bind_name(inclusive_exclusive,low,high)defcheck(value:SupportsLtGe[T])->bool:returnlow<=value<highreturncheck
[docs]definclusive(low:T,high:T)->Predicate[SupportsLeGe[T]]:""" Create a predicate that succeeds when its argument is in the range ``[low, high]``. """@bind_name(inclusive,low,high)defcheck(value:SupportsLeGe[T])->bool:returnlow<=value<=highreturncheck