File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
packages/ni.protobuf.types Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5- from typing import Any
6-
75import numpy as np
86from nitypes .xy_data import XYData
97
1412)
1513
1614
17- def float64_xydata_to_protobuf (value : XYData [Any ], / ) -> xydata_pb2 .DoubleXYData :
15+ def float64_xydata_to_protobuf (value : XYData [np . float64 ], / ) -> xydata_pb2 .DoubleXYData :
1816 """Convert a XYData python object to a protobuf xydata_pb2.DoubleXYData."""
1917 attributes = extended_properties_to_protobuf (value .extended_properties )
2018 xydata_message = xydata_pb2 .DoubleXYData (
Original file line number Diff line number Diff line change @@ -88,17 +88,19 @@ def test___float64_xydata___convert___valid_doublexydata_protobuf() -> None:
8888 assert list (protobuf_value .y_data ) == expected_y_data
8989
9090
91- def test___int16_xydata___convert___valid_doublexydata_protobuf () -> None :
91+ def test___int16_xydata___convert___causes_mypy_error () -> None :
9292 python_value = XYData .from_arrays_1d (
9393 x_array = [1 , 2 , 3 ],
9494 y_array = [4 , 5 , 6 ],
9595 dtype = np .int16 ,
9696 )
9797
98- protobuf_value = float64_xydata_to_protobuf (python_value )
98+ # The next line should generate a mypy error. If it doesn't, we'll get an 'unused
99+ # ignore' mypy error.
100+ protobuf_value = float64_xydata_to_protobuf (python_value ) # type: ignore[arg-type]
99101
102+ # This conversion still works, so we might as well check it. Int values are converted to float.
100103 assert isinstance (protobuf_value , xydata_pb2 .DoubleXYData )
101- # Data values converted to float. Is this OK? Or should we raise an error here?
102104 assert list (protobuf_value .x_data ) == [1.0 , 2.0 , 3.0 ]
103105 assert list (protobuf_value .y_data ) == [4.0 , 5.0 , 6.0 ]
104106
You can’t perform that action at this time.
0 commit comments