Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove const from moduleState #206

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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