[Python-ideas] An ABC representing "Iterable, Sized, Container"
Steven D'Aprano
steve at pearwood.info
Thu Jul 21 22:29:21 EDT 2016
On Thu, Jul 21, 2016 at 01:43:01PM -0700, Guido van Rossum wrote:
> At Dropbox I see a lot of people who want to start using type
> annotations (PEP 484, mypy) struggle with the collection ABCs.
>
> It's pretty common to want to support both sets and lists of values,
> as these have a lot of useful behavior: they are (re)iterable, have a
> size, and implement `__contains__` (i.e. x in c, x not in c). It's
> pretty common for people to think that Iterable is the answer, but
> it's not. I'm beginning to think that it would be useful to add
> another ABC to collections.abc (and to typing) that represents the
> intersection of these three ABCs, and to "upgrade" Set and Sequence to
> inherit from it. (And Mapping.)
Are you talking about giving a nice name to Union[Set, Sequence,
Mapping]?
I'm not sure that there is one, unless we make up a word. How do you
feel about abbreviations? SSM? MSS?
> Thoughts?
>
> (Another useful concept is "reiterable", i.e. an Iterable that can be
> iterated over multiple times -- there's no ABC to indicate this
> concept. Sequence, Set and Mapping all support this concept, Iterator
> does not include it, but Iterable is wishy-washy.)
Now I'm having flash-backs to this thread:
https://mail.python.org/pipermail/python-ideas/2013-September/023239.html
As I recall from that thread:
isinstance(obj, Reiterable)
is *almost* equivalent to:
isinstance(obj, Iterable) and not isinstance(obj, Iterator)
Back at the time, I wasn't convinced that the stdlib needed a special
name for this concept, but I wasn't thinking of the typing module.
--
Steve
More information about the Python-ideas
mailing list