News for hackers. Stuff that matters.
Re:A Python dict that can report which keys you did not use by rjmill on Wednesday July 30, 2025 @02:20PM (#44737746)
Indeed. Inheriting from 'collections.UserDict' instead of 'dict' will make TFA's code work as intended for most of those edge cases.

UserDict will route '.get', '.setdefault', and even iteration via '.items()' through the '__getitem__' method.

edited to remove "(maybe all?) edge cases". As soon as I posted, I thought of several less common/obvious edge cases.

There are no comments on this comment yet.