From ee0de3a71abe325538bb7ef905f737f5cfa360aa Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Sat, 11 Nov 2023 16:37:58 +0100 Subject: [PATCH] feat: add void to PythonConverible --- src/python.ts | 3 ++- test/test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/python.ts b/src/python.ts index f8dc2ba..66cf3bd 100644 --- a/src/python.ts +++ b/src/python.ts @@ -61,6 +61,7 @@ export interface PythonProxy { export type PythonConvertible = | number | bigint + | void | null | undefined | boolean @@ -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; diff --git a/test/test.ts b/test/test.ts index 6338510..d111598 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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"));