"A simple cache returns None both for a missing key and for a key that maps to None."
No, it returns KeyError. Or at least it should.
Perhaps the author has had their fair share of run-ins with libraries that didn't think their API through like that. But yes, they should.
> No, it returns KeyError. Or at least it should.
Surely you meant _raises_? Or did you literally mean to return an exception class?
The author’s example chose to use the syntax that returns None on missing. If they wanted clarity the standard API does raise.
cache = {“key”: “value”, “some input”: None}
cache.get(“missing_key”)
Vs cache[“missing_key”]
There are better examples that could have been highlighted.
it’s maybe less “pythonic” but at $dayjob we’ve very actively moved away from exceptions for things in favor of things that are statically type checked. too many things that become runtime bugs instead of type checking bugs.
with match now being available, we even return explicit error objects and the ergonomics are pretty good (reminds me of rust).