Skip to content

Allow kernels defined from Python REPL #574

@cduck

Description

@cduck

The @kernel decorator currently cannot be used on functions defined from Python's builtin REPL. This should be allowed, even if debug source info is absent.

Example:

% uv run python
Python 3.10.18 (main, Aug  6 2025, 22:40:36) [Clang 20.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from kirin.prelude import basic
>>> @basic
... def func_defined_from_repl():
...     return 1 + 2
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/.venv/lib/python3.10/site-packages/kirin/ir/group.py", line 269, in __call__
    return wrapper(py_func)
  File "/.venv/lib/python3.10/site-packages/kirin/ir/group.py", line 223, in wrapper
    code = self.lowering.python_function(py_func, lineno_offset=lineno_offset)
  File "/.venv/lib/python3.10/site-packages/kirin/lowering/python/lowering.py", line 60, in python_function
    source = textwrap.dedent(inspect.getsource(func))
  File "~/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/inspect.py", line 1139, in getsource
    lines, lnum = getsourcelines(object)
  File "~/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/inspect.py", line 1121, in getsourcelines
    lines, lnum = findsource(object)
  File "~/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/inspect.py", line 958, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions