Skip to content

Commit

Permalink
made a _Numerical DataType
Browse files Browse the repository at this point in the history
Both `Int` and `Float` inherit from it.
  • Loading branch information
evalott100 committed Nov 20, 2024
1 parent 8dab77e commit b8add05
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/fastcs/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit b8add05

Please sign in to comment.