[Python-3000] Generic function PEP won't make it in time (original) (raw)
Bill Janssen janssen at parc.com
Wed Apr 25 02:23:51 CEST 2007
- Previous message: [Python-3000] Generic function PEP won't make it in time
- Next message: [Python-3000] Fixing super anyone?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Maybe "abstraction" is a better keyword than "abstract". > > Maybe it makes sense to have "abstraction" classes, and an > "@ignorethismethod" decorator to mark methods that are not part of > the abstraction, instead of "@abstractmethod" decorators to mark the > methods that are part of the abstraction.
class Iterator(Iterable): @abstract def next(self): raise StopIteration def iter(self): # This is abstract in Iterable, but concrete here return self Both methods are part of the ABC. But only next is abstract. Once could define a perfectly valid empty iterator like this:
If I'm following you correctly, you are saying that "Iterator" is an abstraction class, but the only method which is part of the abstraction is "next".
So it could be marked up as
@abstraction class Iterator(Iterable): @abstractionmethod def next(self): raise StopIteration def iter(self): # This is abstract in Iterable, but concrete here return self
or
@abstraction class Iterator(Iterable): def next(self): raise StopIteration @ignorethismethod def iter(self): # This is abstract in Iterable, but concrete here return self
"Iterator" inherits "iter" from "Iterable", so I think I prefer the idea of explicitly marking the methods which form part of the abstraction (the first form), because it gives you a chance to define new methods with the same name:
@abstraction class Iterator(Iterable): @abstractionmethod def next(self): raise StopIteration @abstractionmethod def iter(self, n): # This is not the iter from Iterable, but a new method return self * n
Bill
- Previous message: [Python-3000] Generic function PEP won't make it in time
- Next message: [Python-3000] Fixing super anyone?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]