This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git


The following commit(s) were added to refs/heads/main by this push:
     new af898a2  feat: Enhance load_module to accept PathLike objects (#187)
af898a2 is described below

commit af898a2c32f053806064ef7b679682f94b5569c1
Author: Tunghohin <[email protected]>
AuthorDate: Fri Oct 24 07:26:39 2025 +0800

    feat: Enhance load_module to accept PathLike objects (#187)
    
    Closes #158
---
 python/tvm_ffi/module.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/python/tvm_ffi/module.py b/python/tvm_ffi/module.py
index 1b53d89..3b09df7 100644
--- a/python/tvm_ffi/module.py
+++ b/python/tvm_ffi/module.py
@@ -21,6 +21,7 @@ from __future__ import annotations
 
 from collections.abc import Sequence
 from enum import IntEnum
+from os import PathLike, fspath
 from typing import TYPE_CHECKING, Any, ClassVar, cast
 
 from . import _ffi_api, core
@@ -305,12 +306,12 @@ def system_lib(symbol_prefix: str = "") -> Module:
     return _ffi_api.SystemLib(symbol_prefix)
 
 
-def load_module(path: str) -> Module:
+def load_module(path: str | PathLike) -> Module:
     """Load module from file.
 
     Parameters
     ----------
-    path
+    path : str | PathLike
         The path to the module file.
 
     Returns
@@ -322,12 +323,19 @@ def load_module(path: str) -> Module:
     --------
     .. code-block:: python
 
-      mod = tvm_ffi.load_module("path/to/module.so")
-      mod.func_name(*args)
+        # Works with string paths
+        mod = tvm_ffi.load_module("path/to/module.so")
+        mod.func_name(*args)
+
+        # Also works with pathlib.Path objects
+        from pathlib import Path
+        mod = tvm_ffi.load_module(Path("path/to/module.so"))
+        mod.func_name(*args)
 
     See Also
     --------
     :py:class:`tvm_ffi.Module`
 
     """
+    path = fspath(path)
     return _ffi_api.ModuleLoadFromFile(path)

Reply via email to