Skip to content
Prev Previous commit
Next Next commit
fix TextIOWrapper.__init__
  • Loading branch information
methane committed Apr 4, 2022
commit 104206a17ca897533da83e85634970a79a82f51b
9 changes: 8 additions & 1 deletion Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,14 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
}
if (encoding == NULL && self->encoding == NULL) {
self->encoding = _Py_GetLocaleEncodingObject();
const PyPreConfig *preconfig = &_PyRuntime.preconfig;
if (preconfig->utf8_mode) {
// TODO: Use _Py_STR
self->encoding = PyUnicode_FromString("utf-8");
}
else {
self->encoding = _Py_GetLocaleEncodingObject();
}
if (self->encoding == NULL) {
goto error;
}
Expand Down