python / python/cpython

C API: Add PyUnicodeWriter_WriteRawStr() function

オープン
#150,973 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core topic-C-API type-feature
主要言語
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 str subclass 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。