<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Jul 20, 2017 05:39, "INADA Naoki" <<a href="mailto:songofacandy@gmail.com">songofacandy@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, Victor.<br>
<div class="quoted-text"><br>
> Why not making abc faster instead of trying to workaround abc for perf<br>
> issue?<br>
<br>
</div>Current ABC provides:<br>
<br>
a) Prohibit instantiating without implement abstract methods.<br>
b) registry based subclassing<br>
<br>
People want Java's interface only wants (a). (b) is unwanted side effect.<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Except (b) is what allows you to subclass an ABC without using the ABC metaclass :-)</div><div dir="auto"><br></div><div dir="auto">I wonder if it would make sense to go further and merge *both* of these features into regular classes.</div><div dir="auto"><br></div><div dir="auto">Checking for @abstractmethod in type.__new__ surely can't be that expensive, can it?</div><div dir="auto"><br></div><div dir="auto">And if regular types supported 'register', then it would allow for a potentially simpler and faster implementation. Right now, superclass.register(subclass) has to work by mutating superclass, because that's the special ABCMeta object, and this leads to complicated stuff with weakrefs and all that. But if this kind of nominal inheritance was a basic feature of 'type' itself, then it could work by doing something like</div><div dir="auto"><br></div><div dir="auto"> subclass.__nominal_bases__ += (superclass,)</div><div dir="auto"><br></div><div dir="auto">and then precalculating the "nominal mro" just like it already precalculates the mro, so issubclass/isinstance would remain fast.</div><div dir="auto"><br></div><div dir="auto">I guess enabling this across the board might cause problems for C classes whose users currently use isinstance to get information about the internal memory layout.</div><div dir="auto"><br></div><div dir="auto">-n</div></div>