[FEAT] Add map_dataclass_to_tuple to make_kwargs_wrapper#515
Merged
tqchen merged 2 commits intoapache:mainfrom Mar 27, 2026
Merged
[FEAT] Add map_dataclass_to_tuple to make_kwargs_wrapper#515tqchen merged 2 commits intoapache:mainfrom
tqchen merged 2 commits intoapache:mainfrom
Conversation
junrushao
approved these changes
Mar 26, 2026
Contributor
There was a problem hiding this comment.
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.
da33697 to
8727d81
Compare
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.
8727d81 to
1feec17
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
map_dataclass_to_tupleparameter tomake_kwargs_wrapperandmake_kwargs_wrapper_from_signaturethat accepts a list of argument names whose dataclass values should be converted to tuples (viadataclasses.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.