Posting this in case someone hits the same issue.
Since python 3.12, UserDict defines it's own get(), which check key in self first. Because __contains__ does not call __missing__, a missing key returns the default instead.
CPython 3.12+ UserDict:
# Modify __contains__ and get() to work like dict
# does when __missing__ is present.
def __contains__(self, key):
return key in self.data
def get(self, key, default=None):
if key in self:
return self[key]
return default
So in 03-dict-set/missing.py, this doctest fails on Python ≥ 3.12:
>>> ud = UserDictSub(A = 'letter A')
>>> ud['a'] # ✅
'letter A'
>>> ud.get('a', '') # ❌
'letter A'
Posting this in case someone hits the same issue.
Since python 3.12, UserDict defines it's own get(), which check
key in selffirst. Because__contains__does not call__missing__, a missing key returns the default instead.CPython 3.12+ UserDict:
So in 03-dict-set/missing.py, this doctest fails on Python ≥ 3.12: