Skip to content

Commit

Permalink
Remove const from moduleState (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Oct 11, 2023
1 parent cd25140 commit ae74db4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pydust/src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn len(object: anytype) !usize {
}

/// Return the runtime module state for a Pydust module definition.
pub fn moduleState(comptime Module: type) !*const Module {
pub fn moduleState(comptime Module: type) !*Module {
if (State.getDefinition(Module).type != .module) {
@compileError("Not a module definition: " ++ Module);
}
Expand Down Expand Up @@ -279,6 +279,8 @@ pub fn tuple(object: anytype) !py.PyTuple {
return py.PyTuple.unchecked(.{ .py = pytuple });
}

/// Return the PyType object for a given Python object.
/// Returns a borrowed reference.
pub fn type_(object: anytype) !py.PyType {
return .{ .obj = .{ .py = @as(
?*ffi.PyObject,
Expand Down
4 changes: 3 additions & 1 deletion pydust/src/types/obj.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ pub fn PyObjectMixin(comptime name: []const u8, comptime prefix: []const u8, com
/// Checked conversion from a PyObject.
pub fn checked(obj: py.PyObject) !Self {
if (PyCheck(obj.py) == 0) {
return py.TypeError.raiseFmt("expected {s}, found {s}", .{ name, try (try py.str(try py.type_(obj))).asSlice() });
const typeName = try py.str(try py.type_(obj));
defer typeName.decref();
return py.TypeError.raiseFmt("expected {s}, found {s}", .{ name, try typeName.asSlice() });
}
return .{ .obj = obj };
}
Expand Down

0 comments on commit ae74db4

Please sign in to comment.