You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by GitBox <gi...@apache.org> on 2026/04/09 23:24:27 UTC
[GH] (tvm-ffi/cherry-pick/c-class-warn-missing-annotations): Workflow run "CI" failed!
The GitHub Actions job "CI" on tvm-ffi.git/cherry-pick/c-class-warn-missing-annotations has failed.
Run started by GitHub user junrushao (triggered by junrushao).
Head commit for run:
ae0a4315027a78fc354a857da623be33c331f4e2 / Junru Shao <ju...@nvidia.com>
feat(c_class): warn when reflected fields lack Python type annotations
When a class decorated with @c_class has C++-reflected fields that are
not accompanied by Python-side type annotations, the decorator now emits
a UserWarning at class-definition time listing the missing names. This
gives library authors an early, actionable signal that IDE support
(autocompletion, type checking, hover docs) is degraded for those fields.
Architecture
------------
The warning logic lives in a new helper, `_warn_missing_field_annotations`,
in `tvm_ffi.registry`. The function is deliberately decoupled from
`register_object` and `_install_dataclass_dunders`: it is a pure
diagnostic that reads `type_info.fields` and `cls.__dict__["__annotations__"]`
without mutating either. `c_class.py` calls it immediately after
`register_object()` succeeds, so the type-info metadata is guaranteed to
be populated but no dunders have been installed yet.
Only fields owned by the current `TypeInfo` node are inspected; parent
fields are the responsibility of the parent class definition. Annotation
lookup uses `cls.__dict__` rather than `getattr(cls, "__annotations__")`
so that inherited annotations from a base class do not falsely suppress
warnings on a child that redefines or extends the field set.
Public Interfaces
-----------------
`_warn_missing_field_annotations` is module-private (single leading
underscore) and not part of the public API surface. External consumers
should not call it directly.
UI/UX
-----
The warning message includes the type key, the qualified class name, and
a sorted list of unannotated field names, plus a concrete remediation
hint ("Add type annotations ..."). `stacklevel` is threaded through so
the warning points at the caller's `@c_class(...)` site, not at the
decorator internals.
Behavioral Changes
------------------
Existing classes that already carry annotations for every reflected field
see zero change. Classes that omit annotations will now emit a
UserWarning during import/definition. This is non-breaking: warnings
are filterable via the standard `warnings` module and do not alter
runtime semantics.
Docs
----
No documentation changes required. The warning itself serves as inline
documentation with an actionable suggestion.
Tests
-----
Five new test cases in `test_dataclass_c_class.py`:
- All fields unannotated -> warning with every field name
- All fields annotated -> no warning
- Partial annotations -> warning lists only the missing subset
- TypeInfo with zero fields -> no warning
- Derived class -> warning mentions only own fields, not parent fields
Untested Edge Cases
-------------------
- Interaction with `warnings.filterwarnings("error")` in downstream
codebases that treat all warnings as exceptions. This is standard
Python semantics and not specific to this feature.
Report URL: https://github.com/apache/tvm-ffi/actions/runs/24218212837
With regards,
GitHub Actions via GitBox
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org