77from typing import Any , Iterable
88
99from google .protobuf import any_pb2
10+ from nitypes .waveform import AnalogWaveform , ComplexWaveform
1011
1112from nipanel .converters import Converter
1213from nipanel .converters .builtin import (
2122from nipanel .converters .protobuf_types import (
2223 BoolCollectionConverter ,
2324 BytesCollectionConverter ,
25+ DigitalWaveformConverter ,
2426 Double2DArrayConverter ,
2527 DoubleAnalogWaveformConverter ,
28+ DoubleComplexWaveformConverter ,
29+ DoubleSpectrumConverter ,
2630 FloatCollectionConverter ,
31+ Int16AnalogWaveformConverter ,
32+ Int16ComplexWaveformConverter ,
2733 IntCollectionConverter ,
2834 ScalarConverter ,
2935 StrCollectionConverter ,
4450 # Protobuf Types
4551 BoolCollectionConverter (),
4652 BytesCollectionConverter (),
53+ DigitalWaveformConverter (),
4754 Double2DArrayConverter (),
4855 DoubleAnalogWaveformConverter (),
56+ DoubleComplexWaveformConverter (),
57+ DoubleSpectrumConverter (),
4958 FloatCollectionConverter (),
59+ Int16AnalogWaveformConverter (),
60+ Int16ComplexWaveformConverter (),
5061 IntCollectionConverter (),
5162 StrCollectionConverter (),
5263 ScalarConverter (),
@@ -73,6 +84,7 @@ def to_any(python_value: object) -> any_pb2.Any:
7384
7485def _get_best_matching_type (python_value : object ) -> str :
7586 underlying_parents = type (python_value ).mro () # This covers enum.IntEnum and similar
87+ additional_info_string = _get_additional_type_info_string (python_value )
7688
7789 container_types = []
7890 value_is_collection = any (_CONVERTIBLE_COLLECTION_TYPES .intersection (underlying_parents ))
@@ -105,7 +117,9 @@ def _get_best_matching_type(python_value: object) -> str:
105117 best_matching_type = None
106118 candidates = _get_candidate_strings (underlying_parents )
107119 for candidate in candidates :
108- python_typename = _create_python_typename (candidate , container_types )
120+ python_typename = _create_python_typename (
121+ candidate , container_types , additional_info_string
122+ )
109123 if python_typename not in _SUPPORTED_PYTHON_TYPES :
110124 continue
111125 best_matching_type = python_typename
@@ -115,7 +129,8 @@ def _get_best_matching_type(python_value: object) -> str:
115129 payload_type = underlying_parents [0 ]
116130 raise TypeError (
117131 f"Unsupported type: ({ container_types } , { payload_type } ) with parents "
118- f"{ underlying_parents } . Supported types are: { _SUPPORTED_PYTHON_TYPES } "
132+ f"{ underlying_parents } .\n \n Supported types are: { _SUPPORTED_PYTHON_TYPES } "
133+ f"\n \n Additional type info: { additional_info_string } "
119134 )
120135 _logger .debug (f"Best matching type for '{ repr (python_value )} ' resolved to { best_matching_type } " )
121136 return best_matching_type
@@ -146,12 +161,24 @@ def _get_candidate_strings(candidates: Iterable[type]) -> list[str]:
146161 candidate_names = []
147162 for candidate in candidates :
148163 candidate_names .append (f"{ candidate .__module__ } .{ candidate .__name__ } " )
149-
150164 return candidate_names
151165
152166
153- def _create_python_typename (candidate_name : str , container_types : Iterable [type ]) -> str :
167+ def _create_python_typename (
168+ candidate_name : str , container_types : Iterable [type ], additional_info : str
169+ ) -> str :
154170 name = candidate_name
171+ if additional_info :
172+ name = f"{ name } [{ additional_info } ]"
155173 for container_type in container_types :
156174 name = f"{ container_type .__module__ } .{ container_type .__name__ } [{ name } ]"
157175 return name
176+
177+
178+ def _get_additional_type_info_string (python_value : object ) -> str :
179+ if isinstance (python_value , AnalogWaveform ):
180+ return str (python_value .dtype )
181+ elif isinstance (python_value , ComplexWaveform ):
182+ return str (python_value .dtype )
183+ else :
184+ return ""
0 commit comments