[Python-3000] Revised PEP 3119 (Abstract Base Classes) (original) (raw)
Samuele Pedroni pedronis at openendsystems.com
Wed May 16 09:35:05 CEST 2007
- Previous message: [Python-3000] Revised PEP 3119 (Abstract Base Classes)
- Next message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message: [Python-3000] Revised PEP 3119 (Abstract Base Classes)
- Next message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]