Skip to content

Why does @c_class require Python field annotations, but not method declarations? #362

@Xseventh

Description

@Xseventh

Hi — question about tvm_ffi.dataclasses.c_class.

Right now @c_class(type_key) fails unless the Python proxy class lists all C++ reflected fields in annotations (otherwise it raises “Missing fields … Defined in C++ but not in Python”). But reflected member functions don’t need any Python-side declaration — they just show up.

This feels inconsistent and makes it hard to generate proxies dynamically (I’d like to create a class directly from reflection metadata without manually duplicating the field list).

Is there a design reason for enforcing the annotation check for fields? If not, would you consider an option like a “non-strict / auto fields” mode where:

if Python has no annotations → auto expose all C++ fields

if Python annotates a subset → expose that subset (no missing-fields error)

still error on extraneous fields (typos)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions