Skip to content

Commit de5bc35

Browse files
committed
feat(kernel): add backward compatibility for kernels API changes
Update `_load_from_hub` function to handle API changes in `select_revision_or_version` and `get_kernel` calls. The changes introduce try-except blocks to catch `TypeError` exceptions, allowing the function to work with both modern keyword-based APIs and older positional argument variants. This ensures compatibility across different versions of the kernels module without breaking existing functionality.
1 parent 95f01ac commit de5bc35

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/twinkle/kernel/function.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ def impl(*args, **kwargs):
3535
from kernels._versions import select_revision_or_version
3636
from kernels.utils import get_kernel
3737
assert repo_id is not None
38-
resolved = select_revision_or_version(repo_id, revision, version)
39-
kernel = get_kernel(repo_id, revision=resolved)
38+
# kernels API changed across versions; use keyword args for modern API
39+
# and fall back to repo_id-only for older variants.
40+
try:
41+
resolved = select_revision_or_version(repo_id, revision=revision, version=version)
42+
except TypeError:
43+
resolved = select_revision_or_version(repo_id)
44+
try:
45+
kernel = get_kernel(repo_id, revision=resolved)
46+
except TypeError:
47+
kernel = get_kernel(repo_id, resolved)
4048
func = getattr(kernel, func_name, None)
4149
if func is None:
4250
raise AttributeError(f'Kernel repo {repo_id} does not export {func_name}.')

0 commit comments

Comments
 (0)