How can I make a field wrapped in Optional
without a default value to be required during deserialization?
#352
Labels
enhancement
New feature or request
Hi! Thank you for the great library!
Let's consider this snippet:
Here, I require the field
b
to be explicitly passed to the constructor ofA
. However,serde
allows not passing the fieldb
during deserialization:Knowing that dacite made the same design choice, I assume this is an intentional thing, not a bug. Is there any available workaround to require being explicit whenever a field is missing a default value?
Also, I would like to share why, to me personally, the current behavior is surprising.
First, because of the mismatch between Python and serde: I cannot create the object without passing the required field in Python, but I can do it via serde. In other words, for serde,
Optional[int]
andOptional[int] = None
are equivalent, which is not intuitive to me.Second, because of the following inconsistency:
What do you think?
The text was updated successfully, but these errors were encountered: