Skip to content

Commit bc51581

Browse files
committed
Add DType union to replace DATATYPE_DTYPES
In future, this should be used in place of DType_T in non-generic contexts and DType_T should be bound to DType, but attempting this revealed some exsiting typing problems that were difficult to resolve. Remove incorrect Table dtype definition. It is actually just ndarray like Waveform.
1 parent c6122bf commit bc51581

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/fastcs/attributes/attribute.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Generic
33

44
from fastcs.attributes.attribute_io_ref import AttributeIORefT
5-
from fastcs.datatypes import DATATYPE_DTYPES, DataType, DType_T
5+
from fastcs.datatypes import DataType, DType, DType_T
66
from fastcs.logging import bind_logger
77
from fastcs.tracer import Tracer
88

@@ -24,9 +24,8 @@ def __init__(
2424
) -> None:
2525
super().__init__()
2626

27-
assert issubclass(datatype.dtype, DATATYPE_DTYPES), (
28-
f"Attr type must be one of {DATATYPE_DTYPES}, "
29-
"received type {datatype.dtype}"
27+
assert issubclass(datatype.dtype, DType), (
28+
f"Attr type must be one of {DType}, received type {datatype.dtype}"
3029
)
3130
self._io_ref = io_ref
3231
self._datatype: DataType[DType_T] = datatype

src/fastcs/datatypes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ._util import numpy_to_fastcs_datatype as numpy_to_fastcs_datatype
22
from .bool import Bool as Bool
3-
from .datatype import DATATYPE_DTYPES as DATATYPE_DTYPES
43
from .datatype import DataType as DataType
4+
from .datatype import DType as DType
55
from .datatype import DType_T as DType_T
66
from .enum import Enum as Enum
77
from .float import Float as Float

src/fastcs/datatypes/datatype.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
from typing import Any, Generic, TypeVar
55

66
import numpy as np
7-
from numpy.typing import DTypeLike
7+
8+
DType = (
9+
int # Int
10+
| float # Float
11+
| bool # Bool
12+
| str # String
13+
| enum.Enum # Enum
14+
| np.ndarray # Waveform / Table
15+
)
816

917
DType_T = TypeVar(
1018
"DType_T",
@@ -13,13 +21,10 @@
1321
bool, # Bool
1422
str, # String
1523
enum.Enum, # Enum
16-
np.ndarray, # Waveform
17-
list[tuple[str, DTypeLike]], # Table
24+
np.ndarray, # Waveform / Table
1825
)
1926
"""A builtin (or numpy) type supported by a corresponding FastCS Attribute DataType"""
2027

21-
DATATYPE_DTYPES: tuple[type] = DType_T.__constraints__ # type: ignore
22-
2328

2429
@dataclass(frozen=True)
2530
class DataType(Generic[DType_T]):

0 commit comments

Comments
 (0)