gemini-code-assist[bot] commented on code in PR #140:
URL: https://github.com/apache/tvm-ffi/pull/140#discussion_r2434354854
##########
tests/python/test_function.py:
##########
@@ -263,3 +263,32 @@ def test_function_from_mlir_packed_safe_call() -> None:
assert sys.getrefcount(keep_alive) == base_ref_count + 1
fadd_one = None
assert sys.getrefcount(keep_alive) == base_ref_count
+
+
+def test_function_subclass() -> None:
+ class JitFunction:
+ def __init__(self, metadata: Any) -> None:
+ self.metadata = metadata
+
+ class MyFunction(tvm_ffi.Function, JitFunction):
+ def __init__(self, metadata: Any) -> None:
+ JitFunction.__init__(self, metadata)
+
+ __call__ = tvm_ffi.Function.__call__ # type: ignore
Review Comment:

To aid future readers, it would be helpful to add a comment explaining why
`__call__` is explicitly reassigned. This is a known subtlety when subclassing
Cython extension types; if `__init__` is overridden, special methods like
`__call__` may not be inherited automatically.
```suggestion
# When subclassing a Cython cdef class and overriding `__init__`,
# special methods like `__call__` may not be inherited automatically.
# This explicit assignment ensures the subclass remains callable.
__call__ = tvm_ffi.Function.__call__ # type: ignore
```
##########
tests/python/test_function.py:
##########
@@ -263,3 +263,32 @@ def test_function_from_mlir_packed_safe_call() -> None:
assert sys.getrefcount(keep_alive) == base_ref_count + 1
fadd_one = None
assert sys.getrefcount(keep_alive) == base_ref_count
+
+
+def test_function_subclass() -> None:
+ class JitFunction:
+ def __init__(self, metadata: Any) -> None:
+ self.metadata = metadata
+
+ class MyFunction(tvm_ffi.Function, JitFunction):
+ def __init__(self, metadata: Any) -> None:
+ JitFunction.__init__(self, metadata)
Review Comment:

To improve clarity, consider adding a comment explaining why
`JitFunction.__init__` is called directly instead of using `super()`. This is a
necessary pattern when mixing a pure Python class with a Cython extension type
like `tvm_ffi.Function` that doesn't have a standard `__init__` method.
```suggestion
# Explicitly initialize the mixin. `super()` is not used because
`tvm_ffi.Function`
# is an extension type without a standard `__init__`.
JitFunction.__init__(self, metadata)
```
--
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]