Skip to content

webassembly: registered JS module function fails with named arguments #18190

@WebReflection

Description

@WebReflection

Port, board and/or hardware

webassembly

MicroPython version

MicroPython v1.27.0-preview-252

Reproduction

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script type="module">
      globalThis.ok = (...args) => {
        console.log("ok", args);
      };

      const base = 'https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@1.27.0-preview-252';
      const { loadMicroPython } = await import(`${base}/micropython.mjs`);
      const interpreter = await loadMicroPython({ url: `${base}/micropython.wasm` });
      interpreter.registerJsModule("issue", {
        test: (...args) => {
          console.log("test", args);
        }
      });
      const { textContent } = document.querySelector('script[type=micropython]');
      await interpreter.runPythonAsync(textContent);
    </script>
    <script type="micropython">
      # regular functions are fine
      from js import ok

      ok("a", { "b": "c" })
      # 'ok' ['a', Proxy(PyProxy)]

      ok("a", b = "c")
      # 'ok' ['a', {}]

      # module functions are weird ...
      from issue import test

      test("a", { "b": "c" })
      # 'test' ['a', Proxy(PyProxy)]

      test("a", b = "c")
      # Uncaught PythonError: Traceback (most recent call last):
      # File "<stdin>", line 8, in <module>
      # TypeError: function expected at most 1 arguments, got 2

      # at proxy_convert_mp_to_js_obj_jsside (micropython.mjs:1:101294)
      # at proxy_convert_mp_to_js_obj_jsside_with_free (micropython.mjs:1:103306)
      # at Object.runPythonAsync (micropython.mjs:1:92725)
      # at (index):20:25
    </script>
  </head>
</html>

Expected behaviour

With latest we tested all our integration tests and everything is fine except the fact we register utilities that accept objects/setup/init references and we are incapable of using the more Pythonic syntax at the Python level which used to work just like these work on globally exposed callbacks.

Something seems off when **kw args are around instead of dictionaries, we expect those named arguments to be passed as dictionary like these do already, and have done, for a while, thanks.

Observed behaviour

The error is thrown for no concrete reason but it's also misleading as it passes two args if no named argument is ued.

Additional Information

@dpgeorge is already aware of this issue which has now been formalized.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions