You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Chapter 3] missing.py doctest failure after python 3.12 (UserDict) #73
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):
returnkeyinself.datadefget(self, key, default=None):
ifkeyinself:
returnself[key]
returndefault
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'
Activity