Skip to content

Add typed PyTuple sequence wrapper - #832

Open
cjdoris wants to merge 1 commit into
mainfrom
codex/add-pytuple-wrapper-type-for-tuples
Open

cjdoris wants to merge 1 commit into
mainfrom
codex/add-pytuple-wrapper-type-for-tuples

Conversation

@cjdoris

@cjdoris cjdoris commented Oct 3, 2026

Copy link
Copy Markdown
Member

Motivation

  • Provide a typed Julia wrapper for Python tuples and sequence-like objects so tuple element types/lengths declared in Julia (T<:Tuple) are respected and conversions behave consistently.
  • Support both statically-known tuple types and vararg/unconstrained tuple types, using the type when it encodes length/element types and falling back to the wrapped Python object's length otherwise.

Description

  • Add PyTuple{T<:Tuple} and constructor in src/API/types.jl and export it from src/API/exports.jl.
  • Implement src/Wrap/PyTuple.jl with ispy, Py, pyconvert_rule_pytuple, IteratorSize/IteratorEltype, eltype, length logic (use the type when fixed else query pylen), size, bounds-checked getindex that converts elements using fieldtype(T,i), iterate, and Base.Tuple materialization via pyconvert.
  • Register a normal-priority pyconvert rule for Python sequences in src/Wrap/Wrap.jl via pyconvert_add_rule("collections.abc:Sequence", PyTuple, pyconvert_rule_pytuple, priority).
  • Add tests covering construction, conversion, indexing, iteration, tuple materialization and a variety of tuple shapes in test/Wrap.jl and test/Convert.jl.

Testing

  • Ran the full Julia test suite with julia --project -e 'using Pkg; Pkg.test()' and the suite passed in this environment (all package tests exercised; PythonCall tests passed).
  • Ran coverage with julia --project -e 'using Pkg; Pkg.test(coverage=true)' and the new src/Wrap/PyTuple.jl code was exercised by tests.
  • Ran the Python tests with uv run pytest -s --nbval ./pytest and all Python tests passed.

Codex Task

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant