diff --git a/qutil/domains.py b/qutil/domains.py index 7d436dc013f920fd3cf39a217db330589f0f5ff1..f386d68a1b82cb505d2d70a38d44549e2a80b9fd 100644 --- a/qutil/domains.py +++ b/qutil/domains.py @@ -156,8 +156,8 @@ class Domain(Container[_RealT], Bounded[_RealT]): @dataclass class Interval(Domain[_RealT], Bounded[_RealT], ABC): """An interval with lower and upper bounds.""" - lower: Bound[_RealT] = Bound[_RealT](default=-inf, integral=False) - upper: Bound[_RealT] = Bound[_RealT](default=+inf, integral=False) + lower: _BoundT[_RealT] = Bound[_RealT](default=-inf, integral=False) + upper: _BoundT[_RealT] = Bound[_RealT](default=+inf, integral=False) precision: int = field(default=16, repr=False) def __and__(self, other: object) -> Domain: @@ -184,8 +184,8 @@ class Interval(Domain[_RealT], Bounded[_RealT], ABC): @dataclass class DiscreteInterval(Interval[_IntegralT], Bounded[_IntegralT]): """A discrete interval that only allows integral values.""" - lower: Bound[_IntegralT] = Bound[_IntegralT](default=-inf, integral=True) - upper: Bound[_IntegralT] = Bound[_IntegralT](default=+inf, integral=True) + lower: _BoundT[_IntegralT] = Bound[_IntegralT](default=-inf, integral=True) + upper: _BoundT[_IntegralT] = Bound[_IntegralT](default=+inf, integral=True) def __contains__(self, value: object) -> bool: return isinstance(value, numbers.Integral) and super().__contains__(value) @@ -236,6 +236,8 @@ class ContinuousInterval(Interval[_RealT]): @dataclass """A rational interval that only allows integral denominators.""" class ReciprocalDiscreteInterval(DiscreteInterval[_IntegralT], Reciprocal[_RealT]): + lower: _BoundT[_IntegralT] = ReciprocalBound[_IntegralT](default=1, integral=True) + upper: _BoundT[_IntegralT] = ReciprocalBound[_IntegralT](default=inf, integral=True) numerator: _RealT = 1.0 def __post_init__(self): @@ -296,8 +298,8 @@ class ReciprocalDiscreteInterval(DiscreteInterval[_IntegralT], Reciprocal[_RealT class BoundedSet(frozenset, Domain[_RealT], Bounded[_RealT]): """A finite set of numbers with lower and upper bounds.""" iterable: InitVar[Iterable[_RealT]] = ... - lower: Bound[_RealT] = Bound[_RealT](-inf, integral=False) - upper: Bound[_RealT] = Bound[_RealT](+inf, integral=False) + lower: _BoundT[_RealT] = Bound[_RealT](default=-inf, integral=False) + upper: _BoundT[_RealT] = Bound[_RealT](default=+inf, integral=False) def __post_init__(self, iterable): super().__init__(iterable)