the dbm docs are vague about what encoding is used when a str is stored
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Documentation
The documentation for the dbm module, eg at https://docs.python.org/3.13/library/dbm.html include an example storing keys and values which are of type str. The documentation says about strings:
Key and values are always stored as [bytes](https://docs.python.org/3.13/library/stdtypes.html#bytes).
This means that when strings are used they are implicitly converted
to the default encoding before being stored.
It is not at all clear to me what "the default encoding" means. For example, one might assume it was the encoding from locale.getenconding() but I think not. Looking at the dbm.sqlite code one sees CAST(? AS BLOB) as the insert parameter placeholder. That says to me that the encoding is whatever the database is using, and that is not apparent to me from looking at the code. And I imagine that the other dbm backends may use other, different, choices for the default encoding.
Ideally I'd like:
- an explicit statement about how the encoding is chosen if that is possible, or a statement that this is backend and possibly current-locale dependent otherwise
- a statement that users should probably always do their own conversion to bytes before storing values if they want control
- possibly an optional
encodingparameter for the dbm.open calls to provide an encoding, with the current (vague but historicly compatible) behaviour if unset, but if provided then an explicit catch ofstrvalues in__setitem__if set, and conversion according to what was provided
I can probably make a PR for the second and third items, and the "backend dependent" flavour of the first one.
Linked PRs
- gh-138030
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
docs.python.org/3.13/library/dbm.html の dbm ドキュメントから始め、dbm.sqlite コードの CAST(? AS BLOB) の処理を調べてください。dbm バックエンドが str 値をどのように扱うかを比較し、その後、エンコーディングの動作を説明し、呼び出し側で制御が必要な場合は値を bytes に変換することを推奨するようドキュメントを更新してください。始める前に、リンクされている PR gh-138030 を確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100