[Python-ideas] An ABC representing "Iterable, Sized, Container"
Nick Coghlan
ncoghlan at gmail.com
Thu Jul 21 22:59:42 EDT 2016
On 22 July 2016 at 10:29, Guido van Rossum <guido at python.org> wrote:
> On Thu, Jul 21, 2016 at 5:05 PM, Thomas Nyberg <tomuxiong at gmail.com> wrote:
>> On 07/21/2016 07:58 PM, Guido van Rossum wrote:
>>>
>>> But there's already Container which means "supports __contains__".
>>>
>>> Collection might cause confusing with the module name collections.
>>>
>>> Otherwise either would be a good candidate...
As far as the original "Sized Iterable Container" question goes, would
FiniteContainer work?
- it's countable/iterable
- it has a quantifiable size
- you can do membership tests on it
Countable & quantifiable = finite, membership testing = container,
hence FiniteContainer
>> Coming out of lurking...
>>
>> StaticIterable? ConstIterable? Something to indicate that if you just
>> iterate over it you keep getting the same thing?
>
> Neither "static" nor "const" convey the right meaning.
>
>> Personally I think Reiterable is about as clear as it ever will be...
>
> Yeah, I think that's my conclusion as well.
With the semantics being "iter(x) is not x"?
That seems reasonable to me, as I spent some time think about whether
or not this is a distinct idea from the "Sized Iterable Container"
question, and it's pretty easy to demonstrate that it is:
>>> class ReiterableCounter:
... def __iter__(self):
... x = 0
... while True:
... yield x
... x += 1
...
>>> ctr = ReiterableCounter()
>>> for x in ctr:
... print(x)
... if x > 1: break
...
0
1
2
>>> for x in ctr:
... print(x)
... if x > 1: break
...
0
1
2
(The same example works by returning any non-terminating iterator from __iter__)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list