Building tuples and lists¶
-
HPyTupleBuilder
HPyTupleBuilder_New
(HPyContext *ctx, HPy_ssize_t size)¶
[source] Create a new tuple builder for
size
elements. The builder is then able to take at mostsize
elements. This function does not raise any exception (even if running out of memory).- Parameters
ctx – The execution context.
size – The number of elements to hold.
-
void
HPyTupleBuilder_Set
(HPyContext *ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item)¶
[source] Assign an element to a certain index of the builder. Valid indices are in range
0 <= index < size
wheresize
is the value passed toHPyTupleBuilder_New()
. This function does not raise * any exception.- Parameters
ctx – The execution context.
builder – A tuple builder handle.
index – The index to assign the object to.
h_item – An HPy handle of the object to store or
HPy_NULL
. Please note that HPy never steals handles and so,h_item
needs to be closed by the caller.
-
HPy
HPyTupleBuilder_Build
(HPyContext *ctx, HPyTupleBuilder builder)¶
[source] Build a tuple from a tuple builder.
- Parameters
ctx – The execution context.
builder – A tuple builder handle.
- Returns
An HPy handle to a tuple containing the values inserted with
HPyTupleBuilder_Set()
orHPy_NULL
in case an error occurred during building or earlier when creating the builder or setting the items.
-
void
HPyTupleBuilder_Cancel
(HPyContext *ctx, HPyTupleBuilder builder)¶
[source] Cancel building of a tuple and free any acquired resources. This function ignores if any error occurred previously when using the tuple builder.
- Parameters
ctx – The execution context.
builder – A tuple builder handle.
-
HPyListBuilder
HPyListBuilder_New
(HPyContext *ctx, HPy_ssize_t size)¶
[source] Create a new list builder for
size
elements. The builder is then able to take at mostsize
elements. This function does not raise any exception (even if running out of memory).- Parameters
ctx – The execution context.
size – The number of elements to hold.
-
void
HPyListBuilder_Set
(HPyContext *ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item)¶
[source] Assign an element to a certain index of the builder. Valid indices are in range
0 <= index < size
wheresize
is the value passed toHPyListBuilder_New()
. This function does not raise any exception.- Parameters
ctx – The execution context.
builder – A list builder handle.
index – The index to assign the object to.
h_item – An HPy handle of the object to store or
HPy_NULL
. Please note that HPy never steals handles and so,h_item
needs to be closed by the caller.
-
HPy
HPyListBuilder_Build
(HPyContext *ctx, HPyListBuilder builder)¶
[source] Build a list from a list builder.
- Parameters
ctx – The execution context.
builder – A list builder handle.
- Returns
An HPy handle to a list containing the values inserted with
HPyListBuilder_Set()
orHPy_NULL
in case an error occurred during building or earlier when creating the builder or setting the items.