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

Ivan Pozdeev vano at mail.mipt.ru
Fri Jun 22 15:30:20 EDT 2018


On 22.06.2018 22:17, Ivan Pozdeev wrote:

On 22.06.2018 22:07, Terry Reedy wrote:

On 6/22/2018 7:17 AM, Christian Tismer wrote:

My problem is to find out how to deal with a class which has getitem but no len. The documentation suggests that the length of a sequence can always be obtained by len(). https://docs.python.org/3/reference/datamodel.html It says that plainly: "The built-in function len() returns the number of items of a sequence. " 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. Now, I know this isn't what https://docs.python.org/3/glossary.html#term-sequence says. But practically, the documentation seems to use "sequence" in the sense "finite iterable". Functions that need to know the length of input in advance seem to be the minority.

-- Regards, Ivan



More information about the Python-Dev mailing list