| | from __future__ import annotations |
| |
|
| | from dataclasses import dataclass |
| | from typing import Generic, TypeVar, Type, Callable, Any |
| |
|
| | from .enums import DataTypeId |
| |
|
| | T = TypeVar("T") |
| |
|
| |
|
| | @dataclass(frozen=True, slots=True) |
| | class DataType(Generic[T]): |
| | """Logical datatype used on ports. |
| | |
| | :param id: stable enum id |
| | :param name: human readable name |
| | :param py_type: Python runtime type |
| | :param encode: optional encoder to JSON safe data |
| | :param decode: optional decoder from JSON safe data |
| | """ |
| | id: DataTypeId |
| | name: str |
| | py_type: Type[T] |
| | encode: Callable[[T], Any] | None = None |
| | decode: Callable[[Any], T] | None = None |
| | color: str = "#888888" |
| |
|