Tuple-like Sequence
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
There are situations where a variable can be either a list or a tuple (or more generally, a sequence), but it is used/unpacked in a tuple-like way. That is, the length is fixed and types are possibly heterogeneous. A practical example of this is mpi4py's buffer specifications.
I don't believe it's possible to express a fixed-length heterogeneous sequence without using Tuple and forcing a specific type/inheritance. It'd be useful to have an abstract type that expresses tuple semantics without the inheritance bounds. So the analogy is roughly: List is to Sequence as Tuple is to FixedSequence (or whatever name we choose).
def foo(x: FixedSequence[int, str]) -> int:
return x[0]
foo((0, ''))
foo([0, ''])
Currently I think it's necessary to do Sequence[Union[int, str]] and this loses both the fixed length and the ordering of the elements in the sequence.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the requested FixedSequence abstraction and compare its semantics with Tuple and Sequence. Done would preserve fixed length, heterogeneous element ordering, and support both tuple and list values as shown in the issue examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100