Support None as start/stop index?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
None is accepted as start and stop index in slices. a[None:i] is equivalent to a[:i] and a[i:None] is equivalent to a[i:], independently from the type of the sequence. It is also accepted as the start or end index in the str, bytes and bytesrray methods index(), count(), startswith() and endswith(). This is not documented and officially supported feature. The documentation contains something like index(value[, start[, end]]), pydoc shows this as well, and inspect.signature() fails for these methods
The start and end indices in the tuple, list, memoryview, array and deque method index() only accept integers (including negative values). It was previously discussed in
- #57549
- #74121
and support of None was even merged, but then reverted.
Sequence.index() supports None since #67275 (although it seems there is a bug for start=None).
This inconsistency is just an annoying nuisance, except that it is difficult to express the default value for the stop index. For in-memory collections we can use sys.maxsize, but currently inspect and pydoc show it as a huge integer value:
>>> inspect.signature(tuple.index)
<Signature (self, value, start=0, stop=9223372036854775807, /)>
I think this is an argument to support None as the stop index (and as the start index for consistency). The possible drawback is that when None was the result of error, this error will no longer be detected.
For now, there were two open ways:
- Declare official support of
Nonein methods which support it de-facto.inspect.signature()will support this. Also, add support ofNonein theindex()methods of other classes (this is very easy now). - Deprecate support of
Nonein methods which support it. This was perhaps an unintentional effect of using a particular private C API. We need support of multisignatures in theinspectandpydocmodules to get and show adequate signatures, but we need this fortuple.index()etc:(value, start=0, /) (value, start, stop, /)
cc @rhettinger
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、slice メソッドとシーケンスメソッドについて記述されている現在の動作を確認し、次に issue #57549、#74121、#67275 を inspect.signature() と pydoc への影響と併せて読んでください。プロジェクトが None インデックスに関する明確で一貫した方針を決定し、文書化されたシグネチャと動作がその決定と一致した時点で、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 30/100