[docs] [issue32500] PySequence_Length() raises TypeError on dict type

Guido van Rossum report at bugs.python.org
Sat Jan 6 12:02:24 EST 2018

Guido van Rossum <guido at python.org> added the comment:

If we were to take the docs literally then PySequence_{Size,Length} should just be aliases for PyObject_Size.  But I'm reluctant to change something that has been like this for ages.

In fact maybe we should deprecate them, together with other PySequence_ and PyMapping_ operations that have more general PyObject_ alternatives?

You can read the source code to find the root cause for the behavior -- PySequence_{Size,Length} only looks for tp_as_sequence->sq_length, but dict has that field set to NULL.  (A dict's size is computed by tp_as_mapping->mp_length.)

Fixing dict by adding a redundant sq_length seems brittle (there may be many other mapping types with similar issues).

So I think we should update the docs to recommend PyObject_Size instead.


Python tracker <report at bugs.python.org>

More information about the docs mailing list