|
1 | 1 | """Classes to convert between measurement specific protobuf types and containers.""" |
2 | 2 |
|
3 | 3 | import collections.abc |
| 4 | +import datetime as dt |
4 | 5 | from typing import Type, Union |
5 | 6 |
|
6 | 7 | import hightime as ht |
@@ -98,26 +99,24 @@ def _value_to_attribute(self, value: ExtendedPropertyValue) -> WaveformAttribute |
98 | 99 |
|
99 | 100 | def to_python_value(self, protobuf_message: DoubleAnalogWaveform) -> AnalogWaveform[np.float64]: |
100 | 101 | """Convert the protobuf DoubleAnalogWaveform to a Python AnalogWaveform.""" |
| 102 | + # Declare timing to accept both bintime and dt.datetime to satisfy mypy. |
| 103 | + timing: Timing[bt.DateTime | dt.datetime] |
101 | 104 | if not protobuf_message.dt and not protobuf_message.HasField("t0"): |
102 | 105 | # If both dt and t0 are unset, use Timing.empty. |
103 | 106 | timing = Timing.empty |
104 | 107 | else: |
105 | 108 | # Timestamp |
106 | 109 | pt_converter = PrecisionTimestampConverter() |
107 | 110 | bin_datetime = pt_converter.to_python_value(protobuf_message.t0) |
108 | | - # TODO: We shouldn't need to convert to dt.datetime here. |
109 | | - # I'm only doing this to avoid a mypy error. This needs to be fixed. |
110 | | - # timestamp = bin_datetime._to_datetime_datetime() |
111 | | - timestamp = bin_datetime |
112 | 111 |
|
113 | 112 | # Sample Interval |
114 | 113 | if not protobuf_message.dt: |
115 | | - timing = Timing.create_with_no_interval(timestamp=timestamp) |
| 114 | + timing = Timing.create_with_no_interval(timestamp=bin_datetime) |
116 | 115 | else: |
117 | 116 | sample_interval = ht.timedelta(seconds=protobuf_message.dt) |
118 | 117 | timing = Timing.create_with_regular_interval( |
119 | 118 | sample_interval=sample_interval, |
120 | | - timestamp=timestamp, |
| 119 | + timestamp=bin_datetime, |
121 | 120 | ) |
122 | 121 |
|
123 | 122 | extended_properties = {} |
|
0 commit comments