C API: Add PyUnicodeWriter_WriteRawStr() function
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Python 3.14 added PyUnicodeWriter_WriteStr() function. In general, writing str(obj) is fine. But there is one exception: writing a str subclass should not call str(obj), otherwise the output can be surprising if the subclass overrides __str__().
The _json and _io were impacted by the str subclass issue. They have been fixed by using the internal C API (_PyUnicodeWriter_WriteStr()). Problem: the internal C API is not usable outside CPython.
The PyUnicodeWriter_WriteStr() documentation has been modified to document a workaround for str subclasses:
To write a
strsubclass which overrides the__str__()method,PyUnicode_FromObject()can be used to get the original string.
Instead of the workaround, I propose adding a PyUnicodeWriter_WriteRawStr() function which handles str subclasses as expected (read the string content, don't use the __str__() method).
Linked PRs
- gh-150974
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まずリンクされた PR gh-150974 を確認し、次に既存の PyUnicodeWriter_WriteStr のドキュメントと、_json および _io にある _PyUnicodeWriter_WriteStr への参照を読みます。PyUnicodeWriter_WriteRawStr() という public API が str() を呼び出さずに str のサブクラスを処理し、ドキュメント化された動作を CPython の内部実装の外部で利用できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- api
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100