gemini-code-assist[bot] commented on code in PR #175:
URL: https://github.com/apache/tvm-ffi/pull/175#discussion_r2443772229


##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -937,7 +957,7 @@ cdef inline int _convert_to_ffi_func_handle(
     return 0
 
 
-def _convert_to_ffi_func(object pyfunc):
+def _convert_to_ffi_func(object pyfunc) -> Function:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyfunc` in `_convert_to_ffi_func` is typed as a generic 
`object`. A more specific type hint `Callable[..., Any]` would be more 
informative and consistent with other parts of the code.
   
   ```
   def _convert_to_ffi_func(pyfunc: Callable[..., Any]) -> Function:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__eq__` is not typed. It should be `object` to 
correctly handle comparisons with any type.
   
   ```
       def __eq__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -104,19 +149,19 @@ cdef class Object:
         else:
             self.chandle = NULL
 
-    def __repr__(self):
+    def __repr__(self) -> str:
         # exception safety handling for chandle=None
         if self.chandle == NULL:
             return type(self).__name__ + "(chandle=None)"
         return str(__object_repr__(self))
 
-    def __eq__(self, other):
+    def __eq__(self, other) -> bool:
         return self.same_as(other)
 
-    def __ne__(self, other):
+    def __ne__(self, other) -> bool:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `other` in `__ne__` is not typed. It should be `object`.
   
   ```
       def __ne__(self, other: object) -> bool:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -37,20 +37,38 @@ def _new_object(cls):
 
 
 class ObjectConvertible:
-    """Base class for all classes that can be converted to object."""
+    """Base class for Python classes convertible to :class:`Object`.
+
+    Subclasses implement :py:meth:`asobject` to produce an
+    :class:`Object` instance used by the FFI runtime.
+    """
 
     def asobject(self):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `asobject` method is missing a return type hint. Based on the docstring, 
it should return an `Object`.
   
   ```
       def asobject(self) -> "Object":
   ```



##########
python/tvm_ffi/cython/error.pxi:
##########
@@ -18,24 +18,45 @@
 
 import types
 import re
+from typing import Callable, Optional
 
-ERROR_NAME_TO_TYPE = {}
-ERROR_TYPE_TO_NAME = {}
+ERROR_NAME_TO_TYPE: dict[str, type] = {}
+ERROR_TYPE_TO_NAME: dict[type, str] = {}
 
-_WITH_APPEND_BACKTRACE = None
-_TRACEBACK_TO_BACKTRACE_STR = None
+_WITH_APPEND_BACKTRACE: Optional[Callable[[BaseException, str], 
BaseException]] = None
+_TRACEBACK_TO_BACKTRACE_STR: Optional[Callable[[types.TracebackType | None], 
str]] = None
 
 
 cdef class Error(Object):
-    """Base class for all FFI errors, usually they are attached to errors
+    """Base class for FFI errors.
 
-    Note
-    ----
-    Do not directly raise this object, instead use the `py_error` method
-    to convert it to a python error then raise it.
+    An :class:`Error` is a lightweight wrapper around a concrete Python
+    exception raised by FFI calls. It stores the error ``kind`` (e.g.
+    ``"ValueError"``), the message, and a serialized FFI backtrace that
+    can be re-attached to produce a Python traceback.
+
+    Users normally interact with specific error subclasses that are
+    registered via :func:`tvm_ffi.error.register_error`.
+
+    Notes
+    -----
+    Do not directly raise this object. Instead, use :py:meth:`py_error`
+    to convert it to a Python exception and raise that.
     """
 
     def __init__(self, kind, message, backtrace):

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameters `kind`, `message`, and `backtrace` in `__init__` are not 
typed. The docstring indicates they are strings. Adding type hints would 
improve clarity and consistency.
   
   ```
       def __init__(self, kind: str, message: str, backtrace: str):
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:
     cdef TVMFFIShapeCell* shape = TVMFFIShapeGetCellPtr((<Object>obj).chandle)
     return tuple(shape.data[i] for i in range(shape.size))
 
 
-def _make_strides_from_shape(tuple shape):
+def _make_strides_from_shape(tuple shape) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `shape` in `_make_strides_from_shape` uses Cython's `tuple` 
type declaration. Using a standard Python type hint `tuple[int, ...]` would be 
more consistent with the rest of the codebase.
   
   ```
   def _make_strides_from_shape(shape: tuple[int, ...]) -> tuple[int, ...]:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `s` in `from_json_str` is not typed. Based on its usage with 
`json.loads`, it should be a string.
   
   ```
       def from_json_str(s: str) -> "TypeSchema":
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -124,9 +130,48 @@ class TypeSchema:
 
     @staticmethod
     def from_json_str(s) -> "TypeSchema":
+        """Construct a :class:`TypeSchema` from a JSON string."""
         return TypeSchema.from_json_obj(json.loads(s))
 
     def repr(self, ty_map = None) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `ty_map` in `repr` is not typed. The docstring indicates it's 
an optional callable. Let's add the corresponding type hint. Using a string 
literal for the type hint avoids needing to import `Callable` here.
   
   ```
       def repr(self, ty_map: "Optional[Callable[[str], str]]" = None) -> str:
   ```



##########
python/tvm_ffi/cython/object.pxi:
##########
@@ -26,7 +26,7 @@ def _set_class_object(cls):
     _CLASS_OBJECT = cls
 
 
-def __object_repr__(obj):
+def __object_repr__(obj) -> str:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `__object_repr__` is not typed. It should be of type 
`Object`.
   
   ```
   def __object_repr__(obj: "Object") -> str:
   ```



##########
python/tvm_ffi/cython/function.pxi:
##########
@@ -959,7 +979,7 @@ cdef inline int _convert_to_opaque_object_handle(
     return 0
 
 
-def _convert_to_opaque_object(object pyobject):
+def _convert_to_opaque_object(object pyobject) -> OpaquePyObject:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `pyobject` in `_convert_to_opaque_object` is typed as a 
generic `object`. Using `Any` would be more idiomatic for type hinting and 
consistent with the rest of the codebase.
   
   ```
   def _convert_to_opaque_object(pyobject: Any) -> OpaquePyObject:
   ```



##########
python/tvm_ffi/cython/tensor.pxi:
##########
@@ -148,38 +150,51 @@ cdef inline int _from_dlpack_universal(
             raise TypeError("Expect from_dlpack to take either a compatible 
tensor or PyCapsule")
 
 
-def from_dlpack(ext_tensor, *, require_alignment=0, require_contiguous=False):
-    """
-    Convert an external tensor to an Tensor.
+def from_dlpack(
+    ext_tensor: Any, *, require_alignment: int = 0, require_contiguous: bool = 
False
+) -> Tensor:
+    """Import a foreign array that implements the DLPack producer protocol.
 
     Parameters
     ----------
     ext_tensor : object
-        The external tensor to convert.
-
-    require_alignment : int
-        The minimum required alignment to check for the tensor.
-
-    require_contiguous : bool
-        Whether to check for contiguous memory.
+        An object supporting ``__dlpack__`` and ``__dlpack_device__``.
+    require_alignment : int, optional
+        If greater than zero, require the underlying data pointer to be
+        aligned to this many bytes. Misaligned inputs raise
+        :class:`ValueError`.
+    require_contiguous : bool, optional
+        When ``True``, require the layout to be contiguous. Non-contiguous
+        inputs raise :class:`ValueError`.
 
     Returns
     -------
-    tensor : :py:class:`tvm_ffi.Tensor`
-        The converted tensor.
+    Tensor
+        A TVM FFI :class:`Tensor` that references the same memory.
+
+    Examples
+    --------
+    .. code-block:: python
+
+        import numpy as np
+        x_np = np.arange(8, dtype="int32")
+        x = tvm_ffi.from_dlpack(x_np)
+        y_np = np.from_dlpack(x)
+        assert np.shares_memory(x_np, y_np)
+
     """
     cdef TVMFFIObjectHandle chandle
     _from_dlpack_universal(ext_tensor, require_alignment, require_contiguous, 
&chandle)
     return make_tensor_from_chandle(chandle)
 
 
 # helper class for shape handling
-def _shape_obj_get_py_tuple(obj):
+def _shape_obj_get_py_tuple(obj) -> tuple[int, ...]:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The parameter `obj` in `_shape_obj_get_py_tuple` is not typed. It should be 
of type `Object`.
   
   ```
   def _shape_obj_get_py_tuple(obj: "Object") -> tuple[int, ...]:
   ```



-- 
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