[Python-3000] Revised PEP 3119 (Abstract Base Classes)
Samuele Pedroni
pedronis at openendsystems.com
Wed May 16 09:35:05 CEST 2007
Guido van Rossum wrote:
> **Open issues:** Conceivably, instead of using the ABCMeta metaclass,
> these classes could override ``__instancecheck__`` and
> ``__subclasscheck__`` to check for the presence of the applicable
> special method; for example::
>
> class Sized(metaclass=ABCMeta):
> @abstractmethod
> def __hash__(self):
> return 0
> @classmethod
> def __instancecheck__(cls, x):
> return hasattr(x, "__len__")
> @classmethod
> def __subclasscheck__(cls, C):
> return hasattr(C, "__bases__") and hasattr(C, "__len__")
>
> This has the advantage of not requiring explicit registration.
> However, the semantics hard to get exactly right given the confusing
> semantics of instance attributes vs. class attributes, and that a
> class is an instance of its metaclass; the check for ``__bases__`` is
> only an approximation of the desired semantics. **Strawman:** Let's
> do it, but let's arrange it in such a way that the registration API
> also works.
>
>
>
just to say that I still think the strawman would be right thing to do.
More information about the Python-3000
mailing list