diff --git a/pydust/src/pytypes.zig b/pydust/src/pytypes.zig index 77e3ad50..4d9e2707 100644 --- a/pydust/src/pytypes.zig +++ b/pydust/src/pytypes.zig @@ -267,12 +267,11 @@ fn Slots(comptime definition: type, comptime name: [:0]const u8) type { return 0; } - fn tp_init_default(pyself: *ffi.PyObject, pyargs: [*c]ffi.PyObject, pykwargs: [*c]ffi.PyObject) callconv(.C) ?*ffi.PyObject { + fn tp_init_default(pyself: *ffi.PyObject, pyargs: [*c]ffi.PyObject, pykwargs: [*c]ffi.PyObject) callconv(.C) c_int { _ = pyself; _ = pykwargs; _ = pyargs; - py.TypeError.raise("Native type cannot be instantiated from Python") catch return null; - return null; + py.TypeError.raise("Native type cannot be instantiated from Python") catch return -1; } /// Wrapper for the user's __del__ function. diff --git a/test/test_classes.py b/test/test_classes.py index 1d0bd606..1a7c5319 100644 --- a/test/test_classes.py +++ b/test/test_classes.py @@ -29,6 +29,11 @@ def test_constructor(): # --8<-- [end:constructor] +def test_non_constructable(): + with pytest.raises(TypeError): + classes.SomeClass() + + # --8<-- [start:subclass] def test_subclasses(): d = classes.Dog("labrador")