タプルオブジェクト (tuple object)

type PyTupleObject

この PyObject のサブタイプは Python のタプルオブジェクトを表現します。

PyTypeObject PyTuple_Type
Part of the Stable ABI.

この PyTypeObject のインスタンスは Python のタプル型を表現します; Python レイヤにおける tuple と同じオブジェクトです。

int PyTuple_Check(PyObject *p)

p がタプルオブジェクトかタプル型のサブタイプのインスタンスである場合に真を返します。この関数は常に成功します。

int PyTuple_CheckExact(PyObject *p)

p がタプルオブジェクトだがタプル型のサブタイプのインスタンスでない場合に真を返します。この関数は常に成功します。

PyObject *PyTuple_New(Py_ssize_t len)
Return value: New reference. Part of the Stable ABI.

サイズが len の新たなタプルオブジェクトを返します。失敗すると NULL を返します。

PyObject *PyTuple_Pack(Py_ssize_t n, ...)
Return value: New reference. Part of the Stable ABI.

サイズが n の新たなタプルオブジェクトを返します。失敗すると NULL を返します。タプルの値は後続の n 個の Python オブジェクトを指す C 引数になります。PyTuple_Pack(2, a, b)Py_BuildValue("(OO)", a, b) と同じです。

Py_ssize_t PyTuple_Size(PyObject *p)
Part of the Stable ABI.

タプルオブジェクトへのポインタを引数にとり、そのタプルのサイズを返します。

Py_ssize_t PyTuple_GET_SIZE(PyObject *p)

タプル p のサイズを返しますが、p は非 NULL でなくてはならず、タプルオブジェクトを指していなければなりません; この関数はエラーチェックを行いません。

PyObject *PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference. Part of the Stable ABI.

p の指すタプルオブジェクト内の、位置 pos にあるオブジェクトを返します。 pos が負であるか範囲を超えている場合、 NULL を返して IndexError 例外をセットします。

PyObject *PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference.

PyTuple_GetItem() に似ていますが、引数に対するエラーチェックを行いません。

PyObject *PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
Return value: New reference. Part of the Stable ABI.

Return the slice of the tuple pointed to by p between low and high, or NULL on failure. This is the equivalent of the Python expression p[low:high]. Indexing from the end of the tuple is not supported.

int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the Stable ABI.

p の指すタプルオブジェクト内の、位置 pos にあるオブジェクトへの参照を入れます。成功すれば 0 を返します。 pos が範囲を超えている場合、 -1 を返して IndexError 例外をセットします。

注釈

この関数は o への参照を "盗み取り" ます。また、変更先のインデクスにすでに別の要素が入っている場合、その要素に対する参照を放棄します。

void PyTuple_SET_ITEM(PyObject *p, Py_ssize_t pos, PyObject *o)

PyTuple_SetItem() に似ていますが、エラーチェックを行わず、新たなタプルに値を入れるとき 以外には使ってはなりません

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

注釈

この関数は o への参照を "盗み取り" ます。また、 PyTuple_SetItem() と違って、要素の置き換えが生じても置き換えられるオブジェクトへの参照を放棄 しません ; その結果、タプル中の位置 pos で参照されていたオブジェクトがメモリリークを引き起こします。

int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize)

タプルをリサイズする際に使えます。 newsize はタプルの新たな長さです。タプルは変更不能なオブジェクト ということになっている ので、この関数はこのオブジェクトに対してただ一つしか参照がない時以外には使ってはなりません。タプルがコード中の他の部分ですでに参照されている場合には、この関数を 使ってはなりません 。タプルは常に指定サイズの末尾まで伸縮します。成功した場合には 0 を返します。クライアントコードは、 *p の値が呼び出し前と同じになると期待してはなりません。 *p が置き換えられた場合、オリジナルの *p は破壊されます。失敗すると -1 を返し、 *pNULL に設定して、 MemoryError または SystemError を送出します。

Struct Sequence オブジェクト

struct sequence オブジェクトは namedtuple() オブジェクトと等価なC オブジェクトです。 つまり、その要素に属性を通してアクセスすることができるシーケンスです。 struct sequence を生成するには、まず特定のstruct sequence 型を生成しなければなりません。

PyTypeObject *PyStructSequence_NewType(PyStructSequence_Desc *desc)
Return value: New reference. Part of the Stable ABI.

後述の desc 中のデータから新しい struct sequence 型を生成します。返される型のインスタンスは PyStructSequence_New() で生成できます。

void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)

struct sequence 型である typedesc をもとにその場で初期化します。

int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)

PyStructSequence_InitType と同じですが、成功した場合には 0 を、失敗した場合には -1 を返します。

バージョン 3.4 で追加.

type PyStructSequence_Desc
Part of the Stable ABI (including all members).

生成するstruct sequence 型のメタデータを保持します。

const char *name

Name of the struct sequence type.

const char *doc

Pointer to docstring for the type or NULL to omit.

PyStructSequence_Field *fields

Pointer to NULL-terminated array with field names of the new type.

int n_in_sequence

Number of fields visible to the Python side (if used as tuple).

type PyStructSequence_Field
Part of the Stable ABI (including all members).

Describes a field of a struct sequence. As a struct sequence is modeled as a tuple, all fields are typed as PyObject*. The index in the fields array of the PyStructSequence_Desc determines which field of the struct sequence is described.

const char *name

Name for the field or NULL to end the list of named fields, set to PyStructSequence_UnnamedField to leave unnamed.

const char *doc

Field docstring or NULL to omit.

const char *const PyStructSequence_UnnamedField
Part of the Stable ABI since version 3.11.

フィールド名を名前がないままするための特殊な値。

バージョン 3.9 で変更: 型が char * から変更されました。

PyObject *PyStructSequence_New(PyTypeObject *type)
Return value: New reference. Part of the Stable ABI.

type のインスタンスを生成します。 typePyStructSequence_NewType() によって事前に生成していなければなりません。

PyObject *PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference. Part of the Stable ABI.

Return the object at position pos in the struct sequence pointed to by p.

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

PyObject *PyStructSequence_GET_ITEM(PyObject *p, Py_ssize_t pos)
Return value: Borrowed reference.

Alias to PyStructSequence_GetItem().

バージョン 3.13 で変更: Now implemented as an alias to PyStructSequence_GetItem().

void PyStructSequence_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
Part of the Stable ABI.

struct sequence ppos の位置にあるフィールドに値 o を設定します。PyTuple_SET_ITEM() のように、生成したてのインスタンスに対してのみ使用すべきです。

Bounds checking is performed as an assertion if Python is built in debug mode or with assertions.

注釈

この関数は o への参照を "盗み取り" ます。

void PyStructSequence_SET_ITEM(PyObject *p, Py_ssize_t *pos, PyObject *o)

Alias to PyStructSequence_SetItem().

バージョン 3.13 で変更: Now implemented as an alias to PyStructSequence_SetItem().