[Python-Dev] PySequence_Check but no __len__
Brett Cannon
brett at python.org
Thu Jun 21 12:29:52 EDT 2018
Sorry, I don't quite follow.
On Thu, 21 Jun 2018 at 08:50 Christian Tismer <tismer at stackless.com> wrote:
> Hi friends,
>
> there is a case in the Python API where I am not sure what to do:
>
> If an object defines __getitem__() only but no __len__(),
> then PySequence_Check() already is true and does not care.
>
Which matches
https://docs.python.org/3/c-api/sequence.html#c.PySequence_Check .
>From Objects/abstract.c:
int
PySequence_Check(PyObject *s)
{
if (PyDict_Check(s))
return 0;
return s != NULL && s->ob_type->tp_as_sequence &&
s->ob_type->tp_as_sequence->sq_item != NULL;
}
>
> So if I define no __len__, it simply fails. Is this intended?
>
What is "it" in this case that is failing? It isn't PySequence_Check() so
I'm not sure what the issue is.
-Brett
>
> I was mislead and thought this was the unlimited case, but
> it seems still to be true that sequences are always finite.
>
> Can someone please enlighten me?
> --
> Christian Tismer-Sperling :^) tismer at stackless.com
> Software Consulting : http://www.stackless.com/
> Karl-Liebknecht-Str. 121 : http://pyside.org
> 14482 Potsdam : GPG key -> 0xE7301150FB7BEE0E
> phone +49 173 24 18 776 <+49%20173%202418776> fax +49 (30) 700143-0023
> <+49%2030%207001430023>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/brett%40python.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180621/3bf0638b/attachment.html>
More information about the Python-Dev
mailing list