Dayuxiaoshui commented on code in PR #411:
URL: https://github.com/apache/tvm-ffi/pull/411#discussion_r2698167265


##########
python/tvm_ffi/dataclasses/_utils.py:
##########
@@ -58,14 +58,13 @@ def type_info_to_cls(
     def _add_method(name: str, func: Callable[..., Any]) -> None:
         if name == "__ffi_init__":
             name = "__c_ffi_init__"
-        if name in attrs:  # already defined
-            return
+        # Allow overriding methods (including from base classes like 
Object.__repr__)
+        # by always adding to attrs, which will be used when creating the new 
class
         func.__module__ = cls.__module__
         func.__name__ = name
         func.__qualname__ = f"{cls.__qualname__}.{name}"
         func.__doc__ = f"Method `{name}` of class `{cls.__qualname__}`"
         attrs[name] = func
-        setattr(cls, name, func)

Review Comment:
   We haven't explicitly tested nested c_class cases yet. The current __repr__ 
implementation uses {self.{field_name}!r} which calls repr() on each field 
value, so nested c_class objects should automatically use their own __repr__ 
methods. I can add a test case to verify this behavior works correctly with 
nested structures.



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