Opaque type for io.TextIOWrapper seek and tell?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
The following prints 18446744073709551620 (as I discovered in https://github.com/python/cpython/issues/93077):
import io
stream = io.TextIOWrapper(io.BytesIO(b'"")\r\nx\r\n'))
stream.read(1)
stream.read(1)
stream.read(1)
print('-----> tell:', stream.tell())
This is not a bug. The documentation says that .tell() returns "an opaque number" that "does not usually represent a number of bytes in the underlying binary storage".
In fact, calling .seek() with anything else than 0 or a return value of .tell() "produces undefined behaviour". I just relied on that today, without knowing it. I wrote this code:
def _upgrade_high_scores_file(file: IO[str], old_version: int) -> None:
...
file.seek(len(b"catris high scores file v"))
...
This shouldn't pass the type check IMO.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、typeshed にある io.TextIOWrapper seek() と tell() のアノテーションを、issue で引用されている Python ドキュメントと併せて確認してください。完全な変更では、tell() の結果を不透明な値として表現し、0 と tell() が返した値は引き続き許可しつつ、seek() が任意のオフセットを受け取らないようにします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100