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.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7R7XHQT2PYHNYAVBXWROFTR72V2FGFXB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to