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/18 00:00:02 UTC
[GH] (tvm-ffi/junrushao/2026-04-17/dataclass-astuple-asdict): Workflow run "CI" failed!
The GitHub Actions job "CI" on tvm-ffi.git/junrushao/2026-04-17/dataclass-astuple-asdict has failed.
Run started by GitHub user junrushao (triggered by junrushao).
Head commit for run:
29479ed78be334218068413ca45abd15577c0e84 / Junru Shao <ju...@nvidia.com>
feat(dataclass): add asdict, astuple, and match_args support
Architecture:
- common.py gains asdict/astuple plus _asdict_inner/_astuple_inner
recursion driven by an _ATOMIC_TYPES frozenset mirroring stdlib
dataclasses. FFI sequence containers (Array, List) recurse to Python
list; FFI mapping containers (Map, Dict) recurse to Python dict so
the result is plain Python data (JSON-ready). Non-dataclass leaves
fall back to copy.deepcopy.
- _dunder.py gains _set_match_args(cls, type_info), a helper that
walks the TypeInfo parent chain parent-first and assembles the
positional __init__ field names (init=True and not kw_only), then
sets cls.__match_args__ if the class does not already define one.
_install_dataclass_dunders accepts a new match_args parameter and
invokes the helper alongside the other dunders.
Public Interfaces:
- tvm_ffi.dataclasses now exports asdict and astuple.
- @py_class and @c_class accept match_args: bool = True, mirroring
stdlib dataclasses. Default preserves prior behavior only when the
class did not override __match_args__; newly decorated classes now
gain __match_args__ automatically.
UI/UX: none.
Behavioral Changes:
- Python 3.10+ match statements against @py_class / @c_class
instances now bind positional captures by field order, matching
stdlib dataclass expectations.
- asdict is a TypeError when passed a type or a non-FFI-dataclass
value, mirroring stdlib.
- _is_ffi_dataclass_instance distinguishes FFI dataclass instances
from FFI container instances (Array/List/Map/Dict), so asdict and
astuple do not mistake containers for dataclasses.
Docs:
- API docs for the new decorator parameter and the two helpers live
in the inline docstrings; no Sphinx RST updates required for this
patch since public names are discovered via __all__.
Tests:
- Executed: uv run pytest tests/python/
- Result: 2184 passed, 38 skipped, 3 xfailed.
- Added TestAsdict (15), TestAstuple (10), TestMatchArgs (11) in
tests/python/test_dataclass_common.py covering inheritance,
init=False, kw_only (field, decorator, KW_ONLY sentinel),
match_args=False opt-out, user-defined __match_args__ override,
FFI Array/List/Map/Dict recursion, dict_factory/tuple_factory, and
error paths.
Untested Edge Cases:
- match statement semantics on Python 3.8/3.9 are not exercised
because match syntax is 3.10+; the __match_args__ tuple is still
populated on older interpreters and is tested there.
- Deeply nested cyclic FFI graphs are not exercised by asdict /
astuple; recursion relies on the caller's graph being acyclic
(same assumption as stdlib dataclasses.asdict).
Report URL: https://github.com/apache/tvm-ffi/actions/runs/24591762407
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