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 using dataclasses-json to load config files into dataclasses and I'm using some enums.
I noticed, that if I load a dictionary using from_dict and there is a key that is mapped to a value that is not of the type in the dataclass and not convertible, it will be overwritten by the default value specified in the dataclass.
This is exactly what I want for a config file, but for Enums, if a string is stored in the dict that can't be converted to the Enum, it will just throw me an ValueError.
Is there a way that I can get the same behaviour as decribes above for Enums? I saw that there is a decoder function that can be specified. But it is only passed the value and not the Enum type or the default.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using dataclasses-json to load config files into dataclasses and I'm using some enums.
I noticed, that if I load a dictionary using from_dict and there is a key that is mapped to a value that is not of the type in the dataclass and not convertible, it will be overwritten by the default value specified in the dataclass.
This is exactly what I want for a config file, but for Enums, if a string is stored in the dict that can't be converted to the Enum, it will just throw me an ValueError.
Is there a way that I can get the same behaviour as decribes above for Enums? I saw that there is a decoder function that can be specified. But it is only passed the value and not the Enum type or the default.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions