[Python-ideas] Fwd: Consider allowing the use of abstractmethod without metaclasses
Nathaniel Smith
njs at pobox.com
Thu Jul 20 20:36:44 EDT 2017
On Jul 20, 2017 05:39, "INADA Naoki" <songofacandy at gmail.com> wrote:
Hi, Victor.
> Why not making abc faster instead of trying to workaround abc for perf
> issue?
Current ABC provides:
a) Prohibit instantiating without implement abstract methods.
b) registry based subclassing
People want Java's interface only wants (a). (b) is unwanted side effect.
Except (b) is what allows you to subclass an ABC without using the ABC
metaclass :-)
I wonder if it would make sense to go further and merge *both* of these
features into regular classes.
Checking for @abstractmethod in type.__new__ surely can't be that
expensive, can it?
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
subclass.__nominal_bases__ += (superclass,)
and then precalculating the "nominal mro" just like it already
precalculates the mro, so issubclass/isinstance would remain fast.
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.
-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170720/c3edb913/attachment.html>
More information about the Python-ideas
mailing list