Author Kirk Hansen
Recipients Kirk Hansen, docs@python
Date 2016-07-18.13:30:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I tried subclassing dict, and overriding its __setitem__ and __getitem__ and got some interesting results. See for an example.

I tried sub-classing UserDict.UserDict and experienced some of the same problems. Eventually, I discovered that subclassing MutableMapping was my best bet.

After an hour or two of searching and reading I discovered that CPython will not call overridden built-in methods of the same object ( This behaviour could (and did) cause some hard to track down bugs in code. 

I briefly looked at the later versions of python documentation and didn't see a mention of this (sorry if it's there), but python2.7 definitely does not mention this. In fact, python2.7 seems to __encourage__ users to subclass the built-ins (see the note Subclassing dict to __extend__ functionality is great, but there should be a big bad warning when trying to __override__ built-ins like __setitem__ and __getitem__.
Date User Action Args
2016-07-18 13:30:51Kirk Hansensetrecipients: + Kirk Hansen, docs@python
2016-07-18 13:30:51Kirk Hansensetmessageid: <>
2016-07-18 13:30:51Kirk Hansenlinkissue27561 messages
2016-07-18 13:30:50Kirk Hansencreate