[Python-ideas] An ABC representing "Iterable, Sized, Container"
Guido van Rossum
guido at python.org
Thu Jul 21 16:43:01 EDT 2016
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.)
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.)
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list