Skip to content

Commit bda3e42

Browse files
author
Michael Johansen
committed
Add a type declaration to satisfy mypy and avoid converting to dt.datetime.
Signed-off-by: Michael Johansen <[email protected]>
1 parent ab69c3d commit bda3e42

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/nipanel/converters/protobuf_types.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Classes to convert between measurement specific protobuf types and containers."""
22

33
import collections.abc
4+
import datetime as dt
45
from typing import Type, Union
56

67
import hightime as ht
@@ -98,26 +99,24 @@ def _value_to_attribute(self, value: ExtendedPropertyValue) -> WaveformAttribute
9899

99100
def to_python_value(self, protobuf_message: DoubleAnalogWaveform) -> AnalogWaveform[np.float64]:
100101
"""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]
101104
if not protobuf_message.dt and not protobuf_message.HasField("t0"):
102105
# If both dt and t0 are unset, use Timing.empty.
103106
timing = Timing.empty
104107
else:
105108
# Timestamp
106109
pt_converter = PrecisionTimestampConverter()
107110
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
112111

113112
# Sample Interval
114113
if not protobuf_message.dt:
115-
timing = Timing.create_with_no_interval(timestamp=timestamp)
114+
timing = Timing.create_with_no_interval(timestamp=bin_datetime)
116115
else:
117116
sample_interval = ht.timedelta(seconds=protobuf_message.dt)
118117
timing = Timing.create_with_regular_interval(
119118
sample_interval=sample_interval,
120-
timestamp=timestamp,
119+
timestamp=bin_datetime,
121120
)
122121

123122
extended_properties = {}

0 commit comments

Comments
 (0)