<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jun 23, 2016 at 8:01 AM, Random832 <span dir="ltr"><<a href="mailto:random832@fastmail.com" target="_blank">random832@fastmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Jun 22, 2016, at 11:11, Guido van Rossum wrote:<br>
> This is done in order to force all mutations of the class dict to go<br>
> through attribute assignments on the class. The latter takes care of<br>
> updating the class struct, e.g. if you were to add an `__add__` method<br>
> dynamically it would update tp_as_number->nb_add. If you could modify the<br>
> dict object directly it would be more difficult to arrange for this side<br>
> effect.<br>
<br>
</span>Why is this different from the fact that updating a normal object's dict<br>
bypasses descriptors and any special logic in __setattr__? Dunder<br>
methods are already "special" in the sense that you can't use them as<br>
object attributes; I wouldn't be surprised by "assigning a dunder method<br>
via the class's dict breaks things".<br></blockquote></div><br></div><div class="gmail_extra">It was a long time when I wrote this, but IIRC the breakage could express itself as a segfault or other C-level crash due to some internal state invariant of the type object being violated, not just an exception. The existence of ctypes notwithstanding, we take C-level crashes very seriously.<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>