diff --git a/python/tvm_ffi/core.pyi b/python/tvm_ffi/core.pyi index afadcd11..9ca9a181 100644 --- a/python/tvm_ffi/core.pyi +++ b/python/tvm_ffi/core.pyi @@ -45,6 +45,15 @@ class Object: def __ne__(self, other: Any) -> bool: ... def __hash__(self) -> int: ... def __init_handle_by_constructor__(self, fconstructor: Function, *args: Any) -> None: ... + def __ffi_init__(self, *args: Any) -> None: + """Initialize the instance using the ` __init__` method registered on C++ side. + + Parameters + ---------- + args: list of objects + The arguments to the constructor + + """ def same_as(self, other: Any) -> bool: ... def _move(self) -> ObjectRValueRef: ... def __move_handle_from__(self, other: Object) -> None: ... @@ -240,6 +249,7 @@ class TypeField: frozen: bool getter: Any setter: Any + dataclass_field: Any | None def as_property(self, cls: type) -> property: ... diff --git a/python/tvm_ffi/cython/object.pxi b/python/tvm_ffi/cython/object.pxi index 3d0e33ee..f0278f0b 100644 --- a/python/tvm_ffi/cython/object.pxi +++ b/python/tvm_ffi/cython/object.pxi @@ -138,6 +138,16 @@ cdef class Object: (fconstructor).chandle, args, &chandle, NULL) self.chandle = chandle + def __ffi_init__(self, *args) -> None: + """Initialize the instance using the `__init__` method registered on the C++ side. + + Parameters + ---------- + args : Any + Positional arguments forwarded to the registered C++ __init__. + """ + self.__init_handle_by_constructor__(type(self)._C___init__, *args) + def same_as(self, other): """Check object identity.