C API: Add PyUnicodeWriter_WriteRawStr() function
Ninguém assumiu esta issue ainda.
- 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
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- 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