[Python-3000] Composable abstract base class?

Guido van Rossum guido at python.org
Sun May 27 11:29:08 CEST 2007


On 5/27/07, Ka-Ping Yee <python at zesty.ca> wrote:
> On Sun, 27 May 2007, Ryan Freckleton wrote:
> > I've been following the python-dev and python 3000 lists for over a
> > year, but this is my first posting.
>
> Hello!

Hello too!

> > I think I've found additional abstract base class to add to PEP 3119.
> > An ABC for composable data (e.g. list, tuple, set, and perhaps dict)
> > to inherit from. An composable object can contain instances of other
> > composable objects. In other words, a composable object can be used as
> > the outer container in a nested data structure.
> [...]
> > def recurse(sequence):
> >       if isinstance(sequence, Composoble):
> >               for child in sequence:
> >                       recurse(child)
> >       else:
> >               print sequence
>
> I think I understand your example, but I don't understand what makes
> it necessary to introduce an ABC for Composable as separate from
> Iterable.  What is intended to be different about Composable?  Can
> you provide a usage example for Composable where Iterable would not
> be sufficient?

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.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list