diff --git a/pytest_pyodide/_decorator_in_pyodide.py b/pytest_pyodide/_decorator_in_pyodide.py index ecb3c8dd..33ce66cc 100644 --- a/pytest_pyodide/_decorator_in_pyodide.py +++ b/pytest_pyodide/_decorator_in_pyodide.py @@ -16,12 +16,13 @@ https://github.com/pyodide/pytest-pyodide/issues/43 """ -import ctypes import pickle from base64 import b64decode, b64encode from io import BytesIO from typing import Any +import pyodide_js + def pointer_to_object(ptr: int) -> Any: """Interpret ptr as a PyObject* and convert it to the actual Python object. @@ -32,7 +33,7 @@ def pointer_to_object(ptr: int) -> Any: # object: use PyObject_SetItem to assign it to a dictionary. # ctypes doesn't seem to have an API to do this directly. temp: dict[int, Any] = {} - ctypes.pythonapi.PyObject_SetItem(id(temp), id(0), ptr) + pyodide_js._module._PyDict_SetItem(id(temp), id(0), ptr) return temp[0] @@ -55,7 +56,7 @@ class Pickler(pickle.Pickler): def persistent_id(self, obj: Any) -> Any: if not isinstance(obj, PyodideHandle): return None - ctypes.pythonapi.Py_IncRef(obj.ptr) + pyodide_js._module._Py_IncRef(obj.ptr) return ("PyodideHandle", obj.ptr)