> > 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
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to