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