python / python/mypy

Tuple-like Sequence

オープン
#8,441 コメント 4 件 リアクション 19 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature needs discussion priority-2-low
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

要求された FixedSequence 抽象化を確認し、そのセマンティクスを Tuple および Sequence と比較します。固定長と異種要素の順序を維持し、issue の例に示されているように、タプル値とリスト値の両方をサポートできれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。