Previously, I added Python "support" for the option type by making it behave like nullable. While this is convenient on the Python programmer's side, it's incompatible with the ATD convention for representing the option type in JSON.
The solution I'm adopting here is:
keep using mypy's Optional type which is a nullable type;
adopt the conventional JSON representation e.g. "None" or ["Some", 42] instead of null or 42, respectively.
Note that ATD's nullable type is still recommended to make JSON code more idiomatic and more readable when it's possible. The only problematic case is with nested nullables since Python null ambiguously represents JSON "None" and JSON ["Some", "None"]. Because of these issues, authors of APIs are advised to not use nested nullables or nested options.
PR checklist
[x] New code has tests to catch future regressions
Fixes #332
Previously, I added Python "support" for the option type by making it behave like nullable. While this is convenient on the Python programmer's side, it's incompatible with the ATD convention for representing the option type in JSON.
The solution I'm adopting here is:
Optional
type which is a nullable type;"None"
or["Some", 42]
instead ofnull
or42
, respectively.Note that ATD's
nullable
type is still recommended to make JSON code more idiomatic and more readable when it's possible. The only problematic case is with nested nullables since Pythonnull
ambiguously represents JSON"None"
and JSON["Some", "None"]
. Because of these issues, authors of APIs are advised to not use nested nullables or nested options.PR checklist
CHANGES.md
is up-to-date