python / python/cpython

Lacking description of how to correctly implement indexing syntax support.

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

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

docs
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Documentation

During a discussion on idea of minimizing requirements for children of collections.abc.Sequence, it was pointed out, that documentation is currently lacking sufficient description on expected behaviour of method __getitem__.

The part in question starts with first note after __length_hint__ description. I started by writing, to see what's missing. Non-trivial changes include:.

  1. Translation of a[1:2, 3:5] into a[(slice(1, 2, None), slice(3, 5, None))].
  2. Because that translation exist, custom behaviour types (like matrix) are also supported.
  3. Slicing should return object of the same type, or at least similar.
  4. If description is good, then note about for loops is unnecessary. (Plus it's outdated, for loops call iter and next, the iterator calls __getitem__).
  5. One object can implement both protocols correctly (at the same time).
  6. Setting __iter__ to None makes iter not fallback to sequence protocol. (And similar point for reversed).
  7. Having ABC as parent, or explicitly assigning methods from them, isn't worst than not defining them at all.
  8. (After coping fallback description from __reversed__, correct that) iter don't need full sequence protocol, just __getitem__ method.
Linked PRs
  • gh-120942
  • gh-122178
  • gh-141124

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

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

はじめの一歩

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

調査の方向性

issueにリンクされたリファレンスに従い、__length_hint__の説明の後にあるPythonデータモデルドキュメントのセクションから開始してください。提案された変更をリンク先のPR gh-120942、gh-122178、gh-141124と比較してください。getitem、スライシング、反復、reversedプロトコルについて列挙された動作が正確に文書化され、古いループに関する注記が解決されていれば完了です。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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