[Python-Dev] PySequence_Check but no len (original) (raw)

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