From b8add0508e34cd21009ffd0929b5dab16c07e7d9 Mon Sep 17 00:00:00 2001 From: Eva Lott Date: Wed, 20 Nov 2024 10:41:01 +0000 Subject: [PATCH] made a `_Numerical` `DataType` Both `Int` and `Float` inherit from it. --- src/fastcs/datatypes.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/fastcs/datatypes.py b/src/fastcs/datatypes.py index 9a0b75a..7ffb815 100644 --- a/src/fastcs/datatypes.py +++ b/src/fastcs/datatypes.py @@ -22,31 +22,32 @@ def dtype(self) -> type[T]: # Using property due to lack of Generic ClassVars pass -@dataclass(frozen=True) -class Int(DataType[int]): - """`DataType` mapping to builtin ``int``.""" +T_Numerical = TypeVar("T_Numerical", int, float) + +@dataclass(frozen=True) +class _Numerical(DataType[T_Numerical]): units: str | None = None min: int | None = None max: int | None = None min_alarm: int | None = None max_alarm: int | None = None + +@dataclass(frozen=True) +class Int(_Numerical[int]): + """`DataType` mapping to builtin ``int``.""" + @property def dtype(self) -> type[int]: return int @dataclass(frozen=True) -class Float(DataType[float]): +class Float(_Numerical[float]): """`DataType` mapping to builtin ``float``.""" prec: int = 2 - units: str | None = None - min: float | None = None - max: float | None = None - min_alarm: float | None = None - max_alarm: float | None = None @property def dtype(self) -> type[float]: