python / python/cpython

Lacking description of how to correctly implement indexing syntax support.

未关闭
#120,802 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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:.

  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. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。