That gets the one-argument API wrong. Calling get(invalid_key) should raise, but your example doesn't, you need an extra keyword argument for that (get(invalid_key, default_is_missing=True)). These APIs already exist all over (including dict.get), so you can't just change their logic, that would break all kinds of code!
Dict.get doesn't use any sentinel values. I think once I need for my code something like sentinel and I ended up with some kind of dispatch: if no value use get_no_value instead of get. In any case it is all different versions of making something for missing function overloading. I think about people who learn coding with Python, and here in stdlib a trick is sold as a right way to write code - standard way to handle undefined. Then we will soon have it every as a valid value (like NaN).
View all comments
Show parent comment
2
u/BlckKnght Jun 08 '21
That gets the one-argument API wrong. Calling
get(invalid_key)should raise, but your example doesn't, you need an extra keyword argument for that (get(invalid_key, default_is_missing=True)). These APIs already exist all over (includingdict.get), so you can't just change their logic, that would break all kinds of code!