gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)

Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().

Unrelated change to please the linter: remove an unused
import in test_ctypes.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Victor Stinner 2025-05-29 16:54:30 +02:00 committed by GitHub
parent 4109a9c6b3
commit f49a07b531
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 103 additions and 31 deletions

View file

@ -979,7 +979,7 @@ contextvar_tp_repr(PyObject *op)
return NULL;
}
if (PyUnicodeWriter_WriteUTF8(writer, "<ContextVar name=", 17) < 0) {
if (PyUnicodeWriter_WriteASCII(writer, "<ContextVar name=", 17) < 0) {
goto error;
}
if (PyUnicodeWriter_WriteRepr(writer, self->var_name) < 0) {
@ -987,7 +987,7 @@ contextvar_tp_repr(PyObject *op)
}
if (self->var_default != NULL) {
if (PyUnicodeWriter_WriteUTF8(writer, " default=", 9) < 0) {
if (PyUnicodeWriter_WriteASCII(writer, " default=", 9) < 0) {
goto error;
}
if (PyUnicodeWriter_WriteRepr(writer, self->var_default) < 0) {
@ -1182,15 +1182,15 @@ token_tp_repr(PyObject *op)
if (writer == NULL) {
return NULL;
}
if (PyUnicodeWriter_WriteUTF8(writer, "<Token", 6) < 0) {
if (PyUnicodeWriter_WriteASCII(writer, "<Token", 6) < 0) {
goto error;
}
if (self->tok_used) {
if (PyUnicodeWriter_WriteUTF8(writer, " used", 5) < 0) {
if (PyUnicodeWriter_WriteASCII(writer, " used", 5) < 0) {
goto error;
}
}
if (PyUnicodeWriter_WriteUTF8(writer, " var=", 5) < 0) {
if (PyUnicodeWriter_WriteASCII(writer, " var=", 5) < 0) {
goto error;
}
if (PyUnicodeWriter_WriteRepr(writer, (PyObject *)self->tok_var) < 0) {