<div dir="ltr">I think inheriting directly from dict is simply bad code because CPython doesn't promise that any of your overridden methods will be called.  The fact that it silently doesn't call them is an inscrutable trap.  And really, it's not much of a "punishment" to simply change your base class name.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 20, 2016 at 11:16 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Apr 20, 2016 at 07:51:37PM -0700, Neil Girdhar wrote:<br>
> Sometimes users inherit from builtin types only to find that their<br>
> overridden methods are not called.  Instead of this being a trap for<br>
> unsuspecting users, I suggest overriding the __new__ method of these types<br>
> so that it will raise with an informative exception explaining that, e.g.,<br>
> instead of inheriting from dict, you should inherit from UserDict.<br>
<br>
-1<br>
<br>
What about those who don't want or need to inherit from UserDict, and<br>
are perfectly happy with inheriting from dict? Why should we break their<br>
working code for the sake of people whose code already isn't working?<br>
<br>
Not everyone who inherits from dict tries to override __getitem__ and<br>
__setitem__ and are then surprised that other methods don't call their<br>
overridden methods. We shouldn't punish them.<br>
<br>
<br>
--<br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/7nFQURLhlQY/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/7nFQURLhlQY/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div>