Build an ``ast.Module`` for a stub kernel with the given type annotations. ``arg_types`` is a list of annotation strings (e.g. ``["int", "float"]``). ``return_type`` is an annotation string (e.g. ``"bool"``) or ``None``.
(arg_types=None, return_type=None)
| 78 | |
| 79 | |
| 80 | def _make_kernel_ast(arg_types=None, return_type=None) -> ast.Module: |
| 81 | """ |
| 82 | Build an ``ast.Module`` for a stub kernel with the given type annotations. |
| 83 | |
| 84 | ``arg_types`` is a list of annotation strings (e.g. ``["int", "float"]``). |
| 85 | ``return_type`` is an annotation string (e.g. ``"bool"``) or ``None``. |
| 86 | """ |
| 87 | params = ", ".join(f"a{i}: {t}" for i, t in enumerate(arg_types or [])) |
| 88 | ret = f" -> {return_type}" if return_type else "" |
| 89 | src = textwrap.dedent(f"""\ |
| 90 | def kernel({params}){ret}: |
| 91 | pass |
| 92 | """) |
| 93 | return ast.parse(src) |
| 94 | |
| 95 | |
| 96 | # -- test cases ------------------------------------------------------------- |
no test coverage detected