Skip to content

Commit 2fb7c5f

Browse files
committed
fix: python.None.valueOf should return null
1 parent f0ee950 commit 2fb7c5f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/python.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,18 @@ export class PyObject {
772772
* a proxy to Python object.
773773
*/
774774
valueOf(): any {
775+
if (
776+
Deno.UnsafePointer.equals(
777+
this.handle,
778+
python.None[ProxiedPyObject].handle,
779+
)
780+
) {
781+
return null;
782+
}
783+
775784
const type = py.PyObject_Type(this.handle);
776785

777-
if (Deno.UnsafePointer.equals(type, python.None[ProxiedPyObject].handle)) {
778-
return null;
779-
} else if (
786+
if (
780787
Deno.UnsafePointer.equals(type, python.bool[ProxiedPyObject].handle)
781788
) {
782789
return this.asBoolean();

test/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,7 @@ def call_the_callback(cb):
384384
pyCallback.destroy();
385385
}
386386
});
387+
388+
Deno.test("None valueOf is null", () => {
389+
assertEquals(python.None.valueOf(), null);
390+
});

0 commit comments

Comments
 (0)