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

tqchen pushed a commit to branch refactor-s2
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 27c21e713e8be1cc85d558c58a16797aae0b1692
Author: tqchen <[email protected]>
AuthorDate: Mon Apr 28 19:48:39 2025 -0400

    Cython FFI module cleanup
---
 python/tvm/ffi/__init__.py       |  1 -
 python/tvm/ffi/_ffi_api.py       |  2 +-
 python/tvm/ffi/container.py      |  4 ++--
 python/tvm/ffi/convert.py        |  4 ++--
 python/tvm/ffi/cython/object.pxi |  5 +++--
 python/tvm/ffi/dtype.py          |  3 ++-
 python/tvm/ffi/error.py          |  2 ++
 python/tvm/ffi/ndarray.py        |  1 +
 python/tvm/ffi/registry.py       | 11 ++++++++---
 tests/lint/pylintrc              |  3 ++-
 10 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/python/tvm/ffi/__init__.py b/python/tvm/ffi/__init__.py
index 6024fa10c3..a6e3920478 100644
--- a/python/tvm/ffi/__init__.py
+++ b/python/tvm/ffi/__init__.py
@@ -23,7 +23,6 @@ This is a standalone module that can be
 from .registry import register_object, register_func, get_global_func, 
_init_api
 from .dtype import dtype
 from .core import String, Bytes
-from .core import Device
 from .core import Object, ObjectGeneric, Function
 from .convert import convert
 from .error import register_error
diff --git a/python/tvm/ffi/_ffi_api.py b/python/tvm/ffi/_ffi_api.py
index 528ba0a464..60bd2463e9 100644
--- a/python/tvm/ffi/_ffi_api.py
+++ b/python/tvm/ffi/_ffi_api.py
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+"""FFI API."""
 from .registry import _init_api
 
 
diff --git a/python/tvm/ffi/container.py b/python/tvm/ffi/container.py
index 42342f74e3..829cf8cf23 100644
--- a/python/tvm/ffi/container.py
+++ b/python/tvm/ffi/container.py
@@ -14,11 +14,11 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+"""Container classes."""
+from typing import Any, List, Dict
 from . import core
 from . import _ffi_api
 from .registry import register_object
-from typing import Any, List, Dict
 
 __all__ = ["Array", "Map"]
 
diff --git a/python/tvm/ffi/convert.py b/python/tvm/ffi/convert.py
index 52b4bf44d2..55cad3f775 100644
--- a/python/tvm/ffi/convert.py
+++ b/python/tvm/ffi/convert.py
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+"""Conversion utilities to bring python objects into ffi values."""
 from numbers import Number
 from typing import Any
 from . import core
@@ -22,7 +22,7 @@ from . import container
 
 
 def convert(value: Any) -> Any:
-    """Convert a python object to value that can be processed by TVM FFI.
+    """Convert a python object to ffi values.
 
     Parameters
     ----------
diff --git a/python/tvm/ffi/cython/object.pxi b/python/tvm/ffi/cython/object.pxi
index 07135bcaa5..36810351c6 100644
--- a/python/tvm/ffi/cython/object.pxi
+++ b/python/tvm/ffi/cython/object.pxi
@@ -164,8 +164,9 @@ def _register_object_by_index(int index, object cls):
 def _object_type_key_to_index(str type_key):
     """get the type index of object class"""
     cdef int32_t tidx
-    CHECK_CALL(TVMFFITypeKeyToIndex(c_str(type_key), &tidx))
-    return tidx
+    if TVMFFITypeKeyToIndex(c_str(type_key), &tidx) == 0:
+        return tidx
+    return None
 
 
 cdef inline object make_ret_object(TVMFFIAny result):
diff --git a/python/tvm/ffi/dtype.py b/python/tvm/ffi/dtype.py
index 5f2f18b5bd..002475c238 100644
--- a/python/tvm/ffi/dtype.py
+++ b/python/tvm/ffi/dtype.py
@@ -14,7 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+"""dtype class."""
+# pylint: disable=invalid-name
 from . import core
 
 
diff --git a/python/tvm/ffi/error.py b/python/tvm/ffi/error.py
index e846e9985a..3592e56271 100644
--- a/python/tvm/ffi/error.py
+++ b/python/tvm/ffi/error.py
@@ -14,6 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+# pylint: disable=invalid-name
+"""Error handling."""
 import types
 import re
 from . import core
diff --git a/python/tvm/ffi/ndarray.py b/python/tvm/ffi/ndarray.py
index b34e95899f..5d51939c27 100644
--- a/python/tvm/ffi/ndarray.py
+++ b/python/tvm/ffi/ndarray.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+"""NDArray related objects and functions."""
 
 from numbers import Integral
 from . import core
diff --git a/python/tvm/ffi/registry.py b/python/tvm/ffi/registry.py
index e4e9925275..164a649431 100644
--- a/python/tvm/ffi/registry.py
+++ b/python/tvm/ffi/registry.py
@@ -14,10 +14,13 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
+"""FFI registry to register function and objects."""
 import sys
 from . import core
 
+# whether we simplify skip unknown objects regtistration
+_SKIP_UNKNOWN_OBJECTS = False
+
 
 def register_object(type_key=None):
     """register object type.
@@ -43,6 +46,8 @@ def register_object(type_key=None):
     def register(cls):
         """internal register function"""
         type_index = core._object_type_key_to_index(object_name)
+        if type_index is None and not _SKIP_UNKNOWN_OBJECTS:
+            raise ValueError("Cannot find object type index for %s" % 
object_name)
         core._register_object_by_index(type_index, cls)
         return cls
 
@@ -115,8 +120,8 @@ def list_global_func_names():
        List of global functions names.
     """
     name_functor = get_global_func("ffi.FunctionListGlobalNamesFunctor")()
-    len = name_functor(-1)
-    return [name_functor(i) for i in range(len)]
+    num_names = name_functor(-1)
+    return [name_functor(i) for i in range(num_names)]
 
 
 def remove_global_func(name):
diff --git a/tests/lint/pylintrc b/tests/lint/pylintrc
index 81e6a9c688..49d6237de7 100644
--- a/tests/lint/pylintrc
+++ b/tests/lint/pylintrc
@@ -123,7 +123,8 @@ disable=
     useless-suppression,
     use-list-literal,
     arguments-renamed,
-    super-init-not-called
+    super-init-not-called,
+    c-extension-no-member
 
 [REPORTS]
 

Reply via email to