Skip to content

Commit

Permalink
feat: add void to PythonConverible (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd authored Nov 13, 2023
1 parent 025e9da commit f1af5b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface PythonProxy {
export type PythonConvertible =
| number
| bigint
| void
| null
| undefined
| boolean
Expand Down Expand Up @@ -434,7 +435,7 @@ export class PyObject {
}

case "object": {
if (v === null) {
if (v === null /*or void*/) {
return python.builtins.None[ProxiedPyObject];
} else if (ProxiedPyObject in v) {
const proxy = v as PythonProxy;
Expand Down
15 changes: 15 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ def call(cb):
cb.destroy();
});

Deno.test("callback returns void", () => {
const { call } = python.runModule(
`
def call(cb):
cb()
`,
"cb_test.py",
);
const cb = python.callback(() => {
// return void
});
call(cb);
cb.destroy();
});

Deno.test("exceptions", async (t) => {
await t.step("simple exception", () => {
assertThrows(() => python.runModule("1 / 0"));
Expand Down

0 comments on commit f1af5b1

Please sign in to comment.