junrushao commented on code in PR #49:
URL: https://github.com/apache/tvm-ffi/pull/49#discussion_r2376805568


##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -109,6 +110,50 @@ class TypeInfo:
     type_cls: Optional[type]
     type_index: int
     type_key: str
+    type_ancestors: list[int]
     fields: list[TypeField]
     methods: list[TypeMethod]
     parent_type_info: Optional[TypeInfo]
+
+    def __post_init__(self):
+        cdef int parent_type_index
+        cdef str parent_type_key
+        if not self.type_ancestors:
+            return
+        parent_type_index = self.type_ancestors[-1]
+        parent_type_key = _type_index_to_key(parent_type_index)
+        self.parent_type_info = 
_lookup_type_info_from_type_key(parent_type_key)  # ensure parent is registered
+
+    def prototype_py(self) -> str:
+        """Generate Python source code for a prototype class of this type.
+
+        The generated class will have the correct inheritance structure and
+        field definitions, but will not have any method definitions.

Review Comment:
   It's not executed and is only used to provide hints to users who want to 
write `@c_class`. Should be pretty copy-paste-ready quality as it looks like:
   
   ```python
   from typing import Any
   from tvm_ffi import dataclasses as D
   from tvm_ffi import core
   
   PARENT_TYPE = core._lookup_type_info_from_type_key('ffi.Object').type_cls
   assert PARENT_TYPE is not None
   
   @D.c_class('testing.TestUnregisteredObject')
   class TestUnregisteredObject(PARENT_TYPE):
     a: Any
     @staticmethod
     def __ffi_init__(*args): ...
   ```



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