On 2020-04-10 11:39 a.m., Greg Ewing wrote:
On 10/04/20 11:43 pm, Soni L. wrote:
it's actually fairly common to deal with KeyError instead of using dict.get or w/e.
When doing that, though, it's good practice to make sure the try/except encloses the minimum amount of code needed.
E.g. instead of
try: value = somedict[get_my_key()] except KeyError: value = something_else()
it's better to write
k = get_my_key() try: value = somedict[k] except KeyError: value = something_else()
Then there's no chance of accidentally swallowing a KeyError produced by get_my_key().
and your custom caching dict raises a KeyError that gets swallowed because of a bug in the cache mechanism. you have solved nothing. the problem still persists. and we still can't get ppl to convert their KeyErrors into RuntimeErrors, or have alternative "error channels" / "exception spaces" other than None. I'll do my part, at least, but unless we make it a pattern (i.e. wrap things in more places, like ValueError in unpacking) it seems like it's gonna be very hard to get ppl to do the same.