| ▲ | RantyDave 2 hours ago | |
"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. | ||
| ▲ | 0cf8612b2e1e an hour ago | parent | next [-] | |
The author’s example chose to use the syntax that returns None on missing. If they wanted clarity the standard API does raise.
Vs
There are better examples that could have been highlighted. | ||
| ▲ | travisd 2 hours ago | parent | prev | next [-] | |
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). | ||
| ▲ | lyorig 2 hours ago | parent | prev [-] | |
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. | ||