Lacking description of how to correctly implement indexing syntax support.
未關閉
還沒有人認領這個 Issue。
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:.
- Translation of
a[1:2, 3:5]intoa[(slice(1, 2, None), slice(3, 5, None))]. - Because that translation exist, custom behaviour types (like matrix) are also supported.
- Slicing should return object of the same type, or at least similar.
- If description is good, then note about for loops is unnecessary. (Plus it's outdated, for loops call
iterandnext, the iterator calls__getitem__). - One object can implement both protocols correctly (at the same time).
- Setting
__iter__toNonemakesiternot fallback to sequence protocol. (And similar point forreversed). - Having ABC as parent, or explicitly assigning methods from them, isn't worst than not defining them at all.
- (After coping fallback description from
__reversed__, correct that)iterdon't need full sequence protocol, just__getitem__method.
Linked PRs
- gh-120942
- gh-122178
- gh-141124
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 length_hint 描述之後的 Python 資料模型文件區段開始,按照 issue 中連結的參考資料進行。將提議的變更與已連結的 PR gh-120942、gh-122178 和 gh-141124 進行比較;當準確記錄了所列出的 getitem、切片、迭代和 reversed 協定行為,並解決了過時的迴圈註記時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100