python / python/cpython

C API: Add PyUnicodeWriter_WriteRawStr() function

Aberta
#150,973 4 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core topic-C-API type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Revise primeiro o PR vinculado gh-150974 e, em seguida, leia a documentação existente de PyUnicodeWriter_WriteStr e as referências em _json e _io a _PyUnicodeWriter_WriteStr. Está concluído quando uma API pública PyUnicodeWriter_WriteRawStr() lidar com subclasses de str sem invocar str(), e o comportamento documentado estiver disponível fora dos componentes internos do CPython.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
c, python
Domínio
api
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.