[Python-3000] Revised PEP 3119 (Abstract Base Classes) (original) (raw)

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