Closed mthuurne closed 1 year ago
Labeling this as "bug" because the current behavior of serializing a None
value to TOML is to silently omit it from the output, when means that it reverts to the default value. Therefore, if the default is not None
, this alters the data on a round trip.
In TOML, unlike JSON and YAML, there is no null value. This means that an optional field (
T | None
annotation) will only be able to have a value ofNone
whenNone
is the default value.For example, for the field
foo: str | None = "bar"
:foo
cannot be assigned the valueNone
foo
beingNone
would be a runtime errorI think it's best to reject unsupported constructs as early as possible, so when the
Binder
is created.The only doubt I have is that if we ever add JSON support, forcing a
None
default on optional fields would be an unnecessary limitation. On the other hand, maybe it's better to focus first on making the best possible TOML binder and not worry about features that don't exist yet.