denosaurs / deno_python

🐍 Python interpreter bindings for Deno and Bun.
https://deno.land/x/python
MIT License
548 stars 17 forks source link

Inspecting a JScallback returns an error #66

Closed sigmaSd closed 3 weeks ago

sigmaSd commented 1 month ago

This requires this pr https://github.com/denosaurs/deno_python/pull/65 to work, otherwise it will segfault

import { python } from "/home/mrcool/dev/deno/others/deno_python/mod.ts";

const inspect = python.import("inspect");
inspect.signature(python.callback(() => {}));
no signature found for builtin <built-in method JSCallback:anonymous of NoneType object at 0x7f218cf558a0>
error: Uncaught (in promise) PythonError: no signature found for builtin <built-in method JSCallback:anonymous of NoneType object at 0x7f218cf558a0>  File "/usr/lib64/python3.12/inspect.py", line 3335, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/inspect.py", line 3075, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/inspect.py", line 2592, in _signature_from_callable
    return _signature_from_builtin(sigcls, obj,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/inspect.py", line 2382, in _signature_from_builtin
    raise ValueError("no signature found for builtin {!r}".format(func))
DjDeveloperr commented 1 month ago

Looks like we need to setup __signature__ attribute

sigmaSd commented 1 month ago

Its not setable,

import { PyObject } from "../others/deno_python/src/python.ts";
import { python } from "/home/mrcool/dev/deno/others/deno_python/mod.ts";

const inspect = python.import("inspect");
const c = PyObject.from(python.callback(() => {}));
c.setAttr("__text_signature__", "hello");

inspect.signature(c);
error: Uncaught (in promise) PythonError: attribute '__text_signature__' of 'builtin_function_or_method' objects is

I feel like the issue is different, the issue is somehow the callbacks are considered builtin despite they're not

sigmaSd commented 1 month ago

Actually maybe its normal that its called builtin, since its coming from the c api, so I guess the question is how to add signature attribute