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
I'm "enhancing" existing code and have to work with some of the more questionable choices when it comes to types.
In this particular case, a field can be either bool or float. When using serialization, it revealed a deficiency that I try to understand.
When executing this, the value is deserialized as 0.0 and I also get a warning that this might happen.
What I don't understand is that a custom decoding function is absolutely straightforward and does the trick. Why is the default behavior not able to handle such cases?
Here is what I used as decoding function
fromsimple_parsing.helpers.serializationimportregister_decoding_fndefdecode_boolean_float(raw_value):
ifisinstance(raw_value, float):
returnraw_valueelifisinstance(raw_value, bool):
returnraw_valueelse:
raiseRuntimeError(f"Could not decode JSON value {raw_value}")
register_decoding_fn(Union[float, bool], decode_boolean_float)
Desktop macOS:
Version 0.1.3
Python 3.9.16
The text was updated successfully, but these errors were encountered:
I'm "enhancing" existing code and have to work with some of the more questionable choices when it comes to types.
In this particular case, a field can be either
bool
orfloat
. When using serialization, it revealed a deficiency that I try to understand.To Reproduce
When executing this, the
value
is deserialized as0.0
and I also get a warning that this might happen.What I don't understand is that a custom decoding function is absolutely straightforward and does the trick. Why is the default behavior not able to handle such cases?
Here is what I used as decoding function
Desktop macOS:
The text was updated successfully, but these errors were encountered: