You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, if a measurement plugin uses an int in the default value of a Float, Double, FloatArray1D, or DoubleArray1D configuration, it gets an error: TypeError: Unexpected type <class 'int'> in the default value for 'float_array_data'. Expected type: <class 'float'>.
TypeError: Unexpected type <class 'int'> in the default value for 'sample_rate'. Expected type: <class 'float'>.
Possible Solution
Add this to _validate_default_value_type_for_basic_type:
if expected_type is float and isinstance(default_value, int):
return
Update tests that check for an error in this case:
FAILED tests/unit/test_metadata.py::test___default_value_different_from_type___validate___raises_type_exception[DataType.Double-1-annotations6] - Failed: DID NOT RAISE <class 'TypeError'>
FAILED tests/unit/test_service.py::test___measurement_service___add_configuration_with_mismatch_default_value__raises_type_error[Float-DataType.Float-1] - Failed: DID NOT RAISE <class 'TypeError'>
Bug Report
In Python,
int
is generally duck-type compatible withfloat
. In most cases, functions that expect afloat
will also accept anint
.Python type checking tools like mypy explicitly support "duck type compatibility" between
int
andfloat
: https://mypy.readthedocs.io/en/stable/duck_type_compatibility.htmlHowever, if a measurement plugin uses an
int
in the default value of aFloat
,Double
,FloatArray1D
, orDoubleArray1D
configuration, it gets an error:TypeError: Unexpected type <class 'int'> in the default value for 'float_array_data'. Expected type: <class 'float'>.
Repro or Code Sample
@measurement_service.configuration("sample_rate", nims.DataType.Double, 1000)
Expected Behavior
It works.
Current Behavior
TypeError: Unexpected type <class 'int'> in the default value for 'sample_rate'. Expected type: <class 'float'>.
Possible Solution
Add this to
_validate_default_value_type_for_basic_type
:Update tests that check for an error in this case:
Context
This came up in the code review for #807
Your Environment
ni-measurement-plugin-sdk-service
version: 1.0.0AB#2819852
The text was updated successfully, but these errors were encountered: