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

Created on 2011-10-06 14:10 by awilkins, last changed 2012-06-23 21:33 by loewis.

Messages (2)
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.
History
Date User Action Args
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