Autobox Python tuple -> Julia Tuple#13
Merged
Merged
Conversation
- box_python_value: match type(val) is tuple exactly, not isinstance. A collections.namedtuple is a tuple subclass; isinstance matched it and silently boxed it as a plain positional Julia Tuple, dropping its field names. Now it falls through to the existing TypeError. - jl2py_box_tuple: check jl_exception_occurred() after jl_call and clear it, matching every other jl_call site in this codebase. Core.tuple is normally total, but an unhandled exception here would otherwise leak into whatever unrelated jl2py_call* runs next. - jl2py_box_tuple: cache the Core.tuple function pointer in a static instead of re-resolving it on every call, matching getproperty_fn's existing pattern in this file. Added a regression test for the namedtuple case; existing suite unaffected (86 passed, 3 skipped, up from 85/3 baseline).
Member
Author
|
Pushed a follow-up commit addressing review feedback on the tuple-boxing code itself:
Added a namedtuple regression test; full suite is 86 passed / 3 skipped (up from 85/3). Separately opened #14 for a GC-rooting issue in |
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.
Closes #12.
box_python_valuehandled bool/int/float/complex/str/None but nottuple, so aPython tuple passed as an arg or kwarg value raised
TypeError: Cannot auto-convert tuple. This blocked tuple-valued Julia kwargs —notably pypiccolo's
SmoothPulseProblem(..., Δt_bounds=(0.1, 0.5))and theminimum_timedemo.Fix: recursively box each element (via
auto_convert_arg, so nested tuples /JuliaValelements work) and build a JuliaTuplewith new Cjl2py_box_tuple(
Core.tuple(elts...), elements rooted across the constructing call). Output side(Julia
Tuple-> Python) already worked via theJuliaTuplewrapper.Tests:
tests/test_tuple_boxing.py— tuple identity, element access,(0.1,0.5) -> Tuple{Float64,Float64}, tuple-as-kwarg-value, empty + nested.Full suite: 85 passed, 3 skipped (Julia 1.12.6).
End-to-end validation against a real Piccolissimo bundle: with this change,
pypiccolo
SmoothPulseProblem(qtraj, N, Q=100.0, R=1e-2, Δt_bounds=(0.1, 0.5))now builds and evaluates (previously
TypeError) — the exact pattern theminimum_timedemo needs.🤖 Generated with Claude Code