oraluben commented on code in PR #187:
URL: https://github.com/apache/tvm-ffi/pull/187#discussion_r2454525526


##########
python/tvm_ffi/module.py:
##########
@@ -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 or PathLike

Review Comment:
   I think it's better to have a valid type expression for python here, e.g. 
`str | PathLike` like the real signature above, unless there's other format in 
docstring?



##########
python/tvm_ffi/module.py:
##########
@@ -322,12 +323,20 @@ 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`
 
     """
-    return _ffi_api.ModuleLoadFromFile(path)
+    # Convert PathLike objects to string

Review Comment:
   It should be sufficient to just use `path = fspath(path)` as in python's 
stdlib:
   
   
https://github.com/python/cpython/blob/bd2c7e8c8b10f4d31eab971781de13844bcd07fe/Lib/posixpath.py#L62-L64



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to