A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-June/153998.html below:

[Python-Dev] PySequence_Check but no __len__

[Python-Dev] PySequence_Check but no __len__ [Python-Dev] PySequence_Check but no __len__Paul Moore p.f.moore at gmail.com
Fri Jun 22 15:35:37 EDT 2018
On 22 June 2018 at 20:17, Ivan Pozdeev via Python-Dev
<python-dev at python.org> wrote:
> On 22.06.2018 22:07, Terry Reedy wrote:

>> https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes
>>
>> says that a Sequence has both __getitem__ and __len__.
>>
>> I am surprised that a C-API function calls something a 'sequence' without
>> it having __len__.
>>
> A practical sequence check is checking for __iter__ . An iterator doesn't
> necessarily have a defined length -- e.g. a stream or a generator.

There's a difference between the ABC "Sequence" and the informally
named sequence concept used in the C API. It's basically just that the
C API term predates the ABC significantly, and there's no way that
we'd change the C API naming because it would break too much code, but
IMO it's just one of those "historical reasons" type of things that
can't really be adequately explained, but just needs to be accepted...

An ABC Sequence has __getitem__ and __len__. In terms of ABCs,
something with __iter__ is an Iterable. Informal terminology is a
different matter...

Paul
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4