Yes, I'm quite sure, since your code above contains "return SENTINAL" and you fixed the bug in your link. (It's also
sentinel.) It's doubly incorrect even in a specification sense, since dict.get defaults to None by returning NULL (it is implemented in C in CPython[0][1], and I'm assuming you can read those references based on your assertion of skill) and no sentinel is used or needed. In your Python translation, that'd be defaulting to None instead of a sentinel. It's triply incorrect because dict.get also does not re-raise a KeyError; it always returns something barring a runtime error of some kind or asking for a key that cannot be hashed:
>>> {}.get({}) is None
TypeError: unhashable type: 'dict'
>>> {}.get("key") is None
True
>>> {}.__hash__ is None
True
>>> "key".__hash__ is None
False
Let me fix your example for you:
def get(self, key, default=None):
try:
return self[key]
except KeyError:
return default
Although really, the C implementation does this, indirectly:
def get(self, key, default=None):
return self[key] if key in self else default
The reason I say indirectly is because (a) there's no exception handling in use in the C case and (b) there's no equivalent to the hash table lookup failing when written in Python, so it's an inexpressible concept. That Python will search twice, while the C does not. The KeyError except is a nice analog, but CPython does not futz with stack frames at all if the key lookup fails, so it's not directly comparable to your version. My final version is the closest you'll get to translating what Python does to Python.
If you're speaking with someone new, you can learn a lot more by not condescendingly assuming competence of the other party, particularly when they correctly spotted those three problems and you didn't. I trust this reply will alleviate the misconception.
[0]: https://github.com/python/cpython/blob/master/Objects/dictob...
[1]: https://github.com/python/cpython/blob/master/Objects/dictob...