On Jul 20, 2017 05:39, "INADA Naoki" <songofaca...@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
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to