-
Notifications
You must be signed in to change notification settings - Fork 49
feat: Expose __ffi_init__ as a de-facto shortcut to calling _C___init__
#31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a convenience initializer method to mirror calling the reflected C++ _C___init__ constructor and exposes an additional field on TypeField.
- Introduces Object.ffi_init as a shortcut to init_handle_by_constructor(type(self).C___init_, ...).
- Updates type stubs accordingly and adds a new dataclass_field attribute to TypeField.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/tvm_ffi/cython/object.pxi | Adds ffi_init convenience wrapper with docstring. |
| python/tvm_ffi/core.pyi | Adds stub for ffi_init and new TypeField.dataclass_field attribute. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| """Initialize the instance using the ` __init__` method registered on C++ side. | ||
| Parameters | ||
| ---------- | ||
| args: list of objects | ||
| The arguments to the constructor |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Same docstring issues as implementation: backticked name contains an extra space ( __init__) and parameter description should reflect variadic positional arguments rather than 'list of objects'. Mirror the corrected wording in the implementation for consistency.
| """Initialize the instance using the ` __init__` method registered on C++ side. | |
| Parameters | |
| ---------- | |
| args: list of objects | |
| The arguments to the constructor | |
| """Initialize the instance using the `__init__` method registered on the C++ side. | |
| Parameters | |
| ---------- | |
| args | |
| Positional arguments to pass to the constructor. |
| offset: int | ||
| frozen: bool | ||
| getter: Any | ||
| setter: Any |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] New attribute dataclass_field is added without any doc/comment explaining its purpose or when it may be None. Consider adding a brief class-level note or inline comment to clarify its role (e.g., link to dataclass reflection mechanism) to aid future maintainability.
| setter: Any | |
| setter: Any | |
| # Reference to the corresponding dataclass field, if the FFI-backed type is also a Python dataclass. | |
| # May be None if no dataclass field is associated (e.g., for non-dataclass types). |
Co-authored-by: Copilot <[email protected]>
|
minor nit, on c function naming, how about |
|
Merged this PR into #8 |
Per discussion w/ @tqchen.
In dataclass-syntax classes as introduced in #8, we likely always use the reflected
_C___init__method to initialize an instance. This PR gives a shortcut to this convention, whereis equivalent to