Skip to content
Snippets Groups Projects
Commit e552fa8b authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Finally proper type hints for lower, upper Bound

parent ef40d5de
No related branches found
No related tags found
1 merge request!102Feature: domains
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment