junrushao opened a new pull request, #488:
URL: https://github.com/apache/tvm-ffi/pull/488

   ## Summary
   
   Rewrite the `@c_class` decorator from a thin `register_object` pass-through 
into
   a `dataclass`-style decorator that combines FFI type registration with 
structural
   dunder methods derived from C++ reflection metadata.
   
   - **`@c_class` now installs structural dunders** — `__init__`, `__repr__`, 
`__eq__`/`__ne__`,
     `__hash__`, and ordering operators (`__lt__`, `__le__`, `__gt__`, 
`__ge__`) — all
     delegating to the corresponding C++ recursive operations (`RecursiveEq`, 
`RecursiveHash`,
     `RecursiveLt`, etc.).
   - **`@dataclass_transform` decorator** added for IDE/type-checker support 
(pyright, mypy).
   - **Slots validation** enforces consistency between `@c_class(slots=...)` 
and the
     class header `slots=` keyword.
   - **Migrate all test objects** in `tvm_ffi.testing` from `@register_object` 
to `@c_class`.
   
   ## Architecture
   
   - `c_class.py`: decorator accepts `init`, `repr`, `eq`, `order`, 
`unsafe_hash`, `slots`
     parameters. Delegates to `register_object` + new 
`_install_dataclass_dunders`.
   - `registry.py`: adds `_install_dataclass_dunders` (installs dunders on 
class),
     `_install_init` (reflection-based `__init__` or guard), `_make_init` / 
`_make_init_signature`
     (builds `inspect.Signature` from C++ field metadata including `kw_only`, 
`has_default`,
     `c_init` traits).
   - Each installed dunder checks `cls.__dict__` before setting, preserving 
user-defined
     overrides.
   - `__eq__`/`__ne__`/ordering return `NotImplemented` for unrelated types, 
following
     Python data model conventions.
   
   ## Public Interfaces
   
   - `@c_class(type_key, *, init, repr, eq, order, unsafe_hash, slots)` — new 
keyword
     arguments; old usage `@c_class("key")` continues to work with sensible 
defaults
     (`init=True`, `repr=True`, others off).
   - No breaking changes — `eq`, `order`, `unsafe_hash` default to `False`.
   
   ## Test Plan
   
   - [x] New `test_dataclass_c_class.py` (30+ tests): custom init preservation,
     auto-generated init with defaults, structural equality (reflexive, 
symmetric),
     hash (dict key, set dedup), ordering (reflexive, antisymmetric), 
different-type
     returns `NotImplemented`, subclass equality, `kw_only` from C++ reflection,
     `init_subset`, derived-derived defaults, slots validation.
   - [x] Renamed `test_copy.py` → `test_dataclass_copy.py` with additional 
cycle/Shape
     coverage and `deep_copy.cc` branch-coverage tests.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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