2 ms·
In my experience (Python and Rust) missing keys are errors, not silently converted to None: In [1]: example = {"foo": None} In [2]: print(example["foo
by lexicality 3y ago
In my experience (Python and Rust) missing keys are errors, not silently converted to None:
In [1]: example = {"foo": None}
In [2]: print(example["foo"])
None
In [3]: print(example["bar"])
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[3], line 1
----> 1 print(example["bar"])
KeyError: 'bar'
In [4]: print(example.get("bar", "sensible default"))
sensible default
If configuration values were arbitrarily nullable I would either need to deal with the possibility of nulls ending up anywhere in my program (back to The Billion Dollar Mistake) or have to have checks on parsing to say which fields are nullable or not.
I acknowledge people have done silly things regarding missing keys already - but I think they should be discouraged from continuing to do so, not enabled.
- donaldstufft 3y agoHow is checking for null any different than checking for the right type in general in TOML?
- rascul 3y ago> In my experience (Python and Rust) missing keys are errors, not silently converted to None: In Rust it's possible to deserialize to an Option. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6e808c8e6a0d2ec197aabe7012ab315 https://play.rust-lang.org/?version=stable&mode=debug&editio...