Skip to content

Commit

Permalink
Fix default tp_init (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Oct 19, 2023
1 parent 2151bf4 commit 5ae9280
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pydust/src/pytypes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions test/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5ae9280

Please sign in to comment.