Skip to content

[FEAT] Add map_dataclass_to_tuple to make_kwargs_wrapper#515

Merged
tqchen merged 2 commits intoapache:mainfrom
tqchen:feat-map-dataclass-to-tuple
Mar 27, 2026
Merged

[FEAT] Add map_dataclass_to_tuple to make_kwargs_wrapper#515
tqchen merged 2 commits intoapache:mainfrom
tqchen:feat-map-dataclass-to-tuple

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented Mar 26, 2026

Add a map_dataclass_to_tuple parameter to make_kwargs_wrapper and make_kwargs_wrapper_from_signature that accepts a list of argument names whose dataclass values should be converted to tuples (via dataclasses.astuple) before being passed to the target function.

This enables callers to pass dataclass instances to FFI functions that expect flattened tuple arguments, matching the calling convention. The conversion is injected into the generated wrapper code, so there is no overhead when the feature is not used.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a map_dataclass_to_tuple parameter to the kwargs_wrapper utility, allowing specified dataclass arguments to be automatically converted to tuples via dataclasses.astuple before being passed to the target function. The implementation updates the dynamic code generation logic to wrap relevant arguments and includes a comprehensive test suite. Feedback suggests adding validation to ensure that all names provided in map_dataclass_to_tuple correspond to actual function parameters, which would help catch typos and provide clearer error messages.

Add a `map_dataclass_to_tuple` parameter to `make_kwargs_wrapper` and
`make_kwargs_wrapper_from_signature` that accepts a list of argument
names whose dataclass values should be converted to tuples (via
`dataclasses.astuple`) before being passed to the target function.

This enables callers to pass dataclass instances to FFI functions that
expect flattened tuple arguments, matching the calling convention used
for NamedTuples (which are already tuples). The conversion is injected
into the generated wrapper code, so there is no overhead when the
feature is not used.
@tqchen tqchen force-pushed the feat-map-dataclass-to-tuple branch 4 times, most recently from da33697 to 8727d81 Compare March 26, 2026 23:51
sphinx-toolbox.utils imports `logger` from `sphinx.ext.autodoc`,
which was removed in Sphinx 9.1.0. sphinx-toolbox 4.1.2 still has
this issue. Pin sphinx<9 until sphinx-toolbox publishes a real fix.
@tqchen tqchen force-pushed the feat-map-dataclass-to-tuple branch from 8727d81 to 1feec17 Compare March 26, 2026 23:51
@tqchen tqchen merged commit dbf64e8 into apache:main Mar 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants