This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tp_as_{number,sequence,mapping} can't be set using PyType_FromSpec
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, awilkins, loewis
Priority: normal Keywords:

Created on 2011-10-06 14:10 by awilkins, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg145013 - (view) Author: Andrew Wilkins (awilkins) Date: 2011-10-06 14:10
I've written an extension using Py_LIMITED_API, and I've created a type using PyType_FromSpec with the slot "Py_sq_length" defined. The slot is not being picked up, i.e. len(MyType()) fails. I can see that tp_as_sequence has not been set, which explains why. All is well if I set it manually (without Py_LIMITED_API defined), like so:
  MyType->tp_as_sequence = &((PyHeapTypeObject*)MyType)->as_sequence;

As far as I can see (docs are lacking), there's no way of setting tp_as_number, tp_as_sequence or tp_as_mapping in types created with PyType_FromSpec. I would expect the presence of any Py_sq_* slots to set tp_as_sequence (likewise for number and mapping).
msg163680 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-06-23 21:33
For 3.3, this is fixed in bb6df3781edb. However, this needs to be backported to 3.2.
msg207280 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2014-01-04 10:37
Since 3.2 has seen its last bugfix release, this won't be added to 3.2 anymore.
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57324
2014-01-04 10:37:30loewissetstatus: open -> closed
resolution: fixed
messages: + msg207280
2012-06-23 21:33:23loewissetmessages: + msg163680
2011-10-06 14:31:02pitrousetnosy: + loewis, amaury.forgeotdarc

type: behavior
versions: + Python 3.3
2011-10-06 14:10:25awilkinscreate