HPy Object

int HPy_IsTrue(HPyContext *ctx, HPy h)
[source]
HPy HPy_GetAttr(HPyContext *ctx, HPy obj, HPy name)
[source]
HPy HPy_GetAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name)
[source]
int HPy_HasAttr(HPyContext *ctx, HPy obj, HPy name)
[source]
int HPy_HasAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name)
[source]
int HPy_SetAttr(HPyContext *ctx, HPy obj, HPy name, HPy value)
[source]
int HPy_SetAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name, HPy value)
[source]
HPy HPy_GetItem(HPyContext *ctx, HPy obj, HPy key)
[source]
HPy HPy_GetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key)
[source]
HPy HPy_GetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx)
[source]
int HPy_SetItem(HPyContext *ctx, HPy obj, HPy key, HPy value)
[source]
int HPy_SetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key, HPy value)
[source]
int HPy_SetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx, HPy value)
[source]
int HPy_DelItem(HPyContext *ctx, HPy obj, HPy key)
[source]
int HPy_DelItem_s(HPyContext *ctx, HPy obj, const char *utf8_key)
[source]
int HPy_DelItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx)
[source]
HPy HPy_Type(HPyContext *ctx, HPy obj)
[source]

Returns the type of the given object obj.

On failure, raises SystemError and returns HPy_NULL. This is equivalent to the Python expression``type(obj)``.

Parameters
  • ctx – The execution context.

  • obj – a Python object (must not be HPy_NULL)

Returns

The type of obj or HPy_NULL in case of errors.

int HPy_TypeCheck(HPyContext *ctx, HPy obj, HPy type)
[source]

Checks if ob is an instance of type or any subtype of type.

Parameters
  • ctx – The execution context.

  • obj – a Python object (must not be HPy_NULL)

  • type – A Python type object. This argument must not be HPy_NULL and must be a type (i.e. it must inherit from Python type). If this is not the case, the behavior is undefined (verification of the argument is only done in debug mode).

Returns

Non-zero if object obj is an instance of type type or an instance of a subtype of type, and 0 otherwise.

int HPy_Is(HPyContext *ctx, HPy obj, HPy other)
[source]
HPy HPy_Repr(HPyContext *ctx, HPy obj)
[source]
HPy HPy_Str(HPyContext *ctx, HPy obj)
[source]
HPy HPy_ASCII(HPyContext *ctx, HPy obj)
[source]
HPy HPy_Bytes(HPyContext *ctx, HPy obj)
[source]
HPy HPy_RichCompare(HPyContext *ctx, HPy v, HPy w, int op)
[source]
int HPy_RichCompareBool(HPyContext *ctx, HPy v, HPy w, int op)
[source]
HPy_hash_t HPy_Hash(HPyContext *ctx, HPy obj)
[source]
int HPy_SetCallFunction(HPyContext *ctx, HPy h, HPyCallFunction *func)
[source]

Set the call function for the given object.

By defining slot HPy_tp_call for some type, instances of this type will be callable objects. The specified call function will be used by default for every instance. This should account for the most common case (every instance of an object uses the same call function) but to still provide the necessary flexibility, function HPy_SetCallFunction allows to set different (maybe specialized) call functions for each instance. This must be done in the constructor of an object.

A more detailed description on how to use that function can be found in section Calling Protocol.

Parameters
  • ctx – The execution context.

  • h – A handle to an object implementing the call protocol, i.e., the object’s type must have slot HPy_tp_call. Otherwise, a TypeError will be raised. This argument must not be HPy_NULL.

  • def – A pointer to the call function definition to set (must not be NULL). The definition is usually created using HPyDef_CALL_FUNCTION

Returns

0 in case of success and -1 in case of an error.