11"""Classes to convert between measurement specific protobuf types and containers."""
22
3- from typing import Any , Type
3+ from typing import Type , TypeAlias , Union
44
55from ni .protobuf .types import scalar_pb2
66from nitypes .scalar import Scalar
77
88from nipanel .converters import Converter
99
10+ _AnyScalarType : TypeAlias = Union [bool , int , float , str ]
1011
11- class ScalarConverter (Converter [Scalar [Any ], scalar_pb2 .ScalarData ]):
12+
13+ class ScalarConverter (Converter [Scalar [_AnyScalarType ], scalar_pb2 .ScalarData ]):
1214 """A converter for Scalar objects."""
1315
1416 @property
@@ -21,7 +23,7 @@ def protobuf_message(self) -> Type[scalar_pb2.ScalarData]:
2123 """The type-specific protobuf message for the Python type."""
2224 return scalar_pb2 .ScalarData
2325
24- def to_protobuf_message (self , python_value : Scalar [Any ]) -> scalar_pb2 .ScalarData :
26+ def to_protobuf_message (self , python_value : Scalar [_AnyScalarType ]) -> scalar_pb2 .ScalarData :
2527 """Convert the Python Scalar to a protobuf scalar_pb2.ScalarData."""
2628 message = self .protobuf_message ()
2729 message .units = python_value .units
@@ -38,7 +40,7 @@ def to_protobuf_message(self, python_value: Scalar[Any]) -> scalar_pb2.ScalarDat
3840
3941 return message
4042
41- def to_python_value (self , protobuf_value : scalar_pb2 .ScalarData ) -> Scalar [Any ]:
43+ def to_python_value (self , protobuf_value : scalar_pb2 .ScalarData ) -> Scalar [_AnyScalarType ]:
4244 """Convert the protobuf message to a Python Scalar."""
4345 if protobuf_value .units is None :
4446 raise ValueError ("protobuf.units cannot be None." )
0 commit comments