[New-bugs-announce] [issue13115] tp_as_{number, sequence, mapping} can't be set using PyType_FromSpec

Andrew Wilkins report at bugs.python.org
Thu Oct 6 16:10:26 CEST 2011

New submission from Andrew Wilkins <axwalk at gmail.com>:

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).

components: Interpreter Core
messages: 145013
nosy: awilkins
priority: normal
severity: normal
status: open
title: tp_as_{number,sequence,mapping} can't be set using PyType_FromSpec
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list