[Python-3000] Composable abstract base class?

Nick Coghlan ncoghlan at gmail.com
Sun May 27 12:18:45 CEST 2007


Guido van Rossum wrote:
> Ryan is repeating the classic flatten example: strings are iterables
> but shouldn't be iterated over in this example. This is more the
> domain of Generic Functions, PEP 3124. Anyway, the beauty of PEP 3119
> is that even if PEP 3124 were somehow rejected, you could add
> Composable yourself, and there is no requirement to add it (or any
> other category you might want to define) to the "standard" set of
> ABCs.

I think this is an interesting example to flesh out though - how would I 
express that most instances of Iterable should be iterated over when 
being Flattened, but that certain instances of Iterable (i.e. strings) 
should be ignored?

For example, it would be nice to be able to write:

   from abc import Iterable

   class Flattenable(Iterable):
       pass

   Flattenable.deregister(basestring)


Reading the PEP as it stands, I believe carving out exceptions like this 
would require either subclassing ABCMeta to change the behaviour, or 
else relying on PEP 3124 or some other generic function mechanism.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list