hpy
hpy copied to clipboard
Enable exact type checks with HPy_TypeCheck
In CPython, there are usually macros like:
#define PySomething_Check(op) PyObject_TypeCheck(op, &PySomething_Type)
#define PySomething_CheckExact(op) (Py_TYPE(op) == &PySomething_Type)
That translates to following in HPy:
// PySomething_Check
HPy_TypeCheck(ctx, h_obj, h_type)
// PySomething_CheckExact(op)
HPy_Is(ctx, HPy_Type(ctx, h_obj), h_type)
As it turns out, the exact type check is pretty verbose in HPy and having two API calls may also be a high performance drawback.
An alternative approach would be to have a new API for that. Something like HPy_TypeCheckExact
(which would come with a new context function as well).