The GitHub Actions job "mainline-only" on tvm-ffi.git/main has succeeded. Run started by GitHub user junrushao (triggered by junrushao).
Head commit for run: 6973d225eb3c67a7c306e36b20a100c5e9ff46f7 / Junru Shao <[email protected]> feat(python): wire __init__ from C++ reflection in register_object and stubgen (#491) ## Summary Wire `__init__` from C++ reflection metadata in both `register_object` (runtime) and `tvm-ffi-stubgen` (static stubs), so that registered classes with `refl::init()` work out of the box without `@c_class`. ## Architecture - **`stub/utils.py`**: New `InitFieldInfo` / `ObjectInfo.gen_init()` walk the TypeInfo parent chain to collect `c_init`, `c_kw_only`, `c_has_default` flags per field, emitting typed `__init__` stubs via `_gen_auto_init` (KWARGS protocol with proper signature) or `_gen_c_init` (positional pass-through from `__c_ffi_init__`). - **`stub/codegen.py`**: `generate_object()` now calls `gen_init()` and injects the result into the `TYPE_CHECKING` block before method stubs. - **`registry.py`**: `register_object._register()` calls `_install_init(cls, enabled=True)` after `_add_class_attrs`, wiring `__init__` → `__ffi_init__` for any class whose C++ `ObjectDef` registered `refl::init()`. - **`_install_init`**: When `enabled=True` and no `__ffi_init__` exists, returns silently instead of installing a TypeError guard — backward-compatible for `Object()` and unregistered subclasses. The `enabled=False` guard (used by `@c_class(init=False)`) is unchanged. - Removed duplicate `_install_init` definition that shadowed the primary one after rebase. ## Public Interfaces - `register_object` now auto-wires `__init__` when C++ `__ffi_init__` exists; previously only `@c_class` did this. - `core.pyi`: Added `TypeField.c_init`, `c_kw_only`, `c_has_default` and `TypeInfo.type_ancestors` stubs. - Slots docstrings updated: recommend `__slots__ = ("__dict__",)` instead of the removed `slots=False` metaclass keyword. ## Behavioral Changes - Registered classes with `__ffi_init__` (non-auto-init) get `__init__ = __ffi_init__` automatically — fixes `IntPair(1, 2)` in `examples/python_packaging`. - Classes without `__ffi_init__` keep default `object.__init__` behavior (no guard installed). - `@c_class(init=False)` still installs a `TypeError` guard as before. - 30 unnecessary `ty: ignore` comments removed after stubgen generates proper `__init__` signatures. ## Test Plan - [x] Pre-commit hooks pass (ruff check, ruff format, ty check, cython-lint, clang-format, ASF headers) - [x] Full `pytest tests/python` (requires build) - [x] `examples/python_packaging` end-to-end (requires build + `uv pip install`) - [x] C++ tests unaffected (no C++ changes) ## Untested Edge Cases - stubgen `_gen_c_init` on packages whose shared library is not loaded at stubgen time (the metadata would be unavailable; no crash, just no `__init__` emitted). - Interaction of auto-wired `__init__` with `__init_subclass__` hooks on deeply nested Object hierarchies. Report URL: https://github.com/apache/tvm-ffi/actions/runs/22556204601 With regards, GitHub Actions via GitBox --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
