[Python-ideas] An ABC representing "Iterable, Sized, Container"
Michael Selik
michael.selik at gmail.com
Thu Jul 21 17:14:21 EDT 2016
On Thu, Jul 21, 2016 at 4:43 PM Guido van Rossum <guido at python.org> 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
>
Are these folks dissatisfied with a union type: ``Union[Sequence, Set]``?
(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.)
>
"Reiterable" seems to cause vocabulary confusion regularly on this list. It
also has a common case for runtime checking:
if not isinstance(iterable, Reiterable):
iterable = list(iterable)
It's hard to think of a good name to describe ``Union[Iterable, Sized,
Container]`` and it'd still have the confusion of whether it's re-iterable.
Does the concept of "reiterable" imply that an iteration does not mutate
the object? If so, then if something is both Reiterable and Sized, it
should also be a Container.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160721/bf2cac83/attachment.html>
More information about the Python-ideas
mailing list