hpy
hpy copied to clipboard
Ambiguous tests in test_hpytype_legacy.py
The code in test_htype.py
has tests like
def test_simple_type(self):
mod = self.make_module("""
static HPyType_Spec Dummy_spec = {
.name = "mytest.Dummy",
.itemsize = 0,
.flags = HPy_TPFLAGS_DEFAULT | HPy_TPFLAGS_BASETYPE,
@DEFAULT_SHAPE
};
@EXPORT_TYPE("Dummy", Dummy_spec)
@INIT
""")
When run in test_hpytype.py
then @DEFAULT_SHAPE
is an empty comment "/* default object shape */"
and everything is fine. But when these tests are rerun in test_hpytype_legacy.py
, then @DEFAULT_SHAPE
becomes .builtin_shape = HPyType_BuiltinShape_Legacy
.
As I understand the intention of using the legacy shape is that the type can be used via the C-API, so it needs to become a heap type object. But the preamble to add #include <Python.h>
is missing, and the basicsize
is 0 (not declared). I guess I can work around the missing include file somehow, but it is not clear to me if a type spec can declare legacy shape without declaring a basicsize. Thoughts? Should this Just Work (i.e. when creating a type from the spec, note the legacy flag and allocate a heap type object as the storage)?