if (encoding == NULL || encoding == Py_None) {
PyInterpreterState *interp = _PyInterpreterState_GET();
if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) {
- PyErr_WarnEx(PyExc_EncodingWarning,
- "'encoding' argument not specified", stacklevel);
+ if (PyErr_WarnEx(PyExc_EncodingWarning,
+ "'encoding' argument not specified", stacklevel)) {
+ return NULL;
+ }
}
Py_INCREF(_PyIO_str_locale);
return _PyIO_str_locale;
self->ok = 0;
self->detached = 0;
+ if (encoding == NULL) {
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) {
+ if (PyErr_WarnEx(PyExc_EncodingWarning,
+ "'encoding' argument not specified", 1)) {
+ return -1;
+ }
+ }
+ }
+ else if (strcmp(encoding, "locale") == 0) {
+ encoding = NULL;
+ }
+
if (errors == Py_None) {
errors = _PyUnicode_FromId(&PyId_strict); /* borrowed */
if (errors == NULL) {
self->encodefunc = NULL;
self->b2cratio = 0.0;
- if (encoding == NULL) {
- PyInterpreterState *interp = _PyInterpreterState_GET();
- if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) {
- PyErr_WarnEx(PyExc_EncodingWarning,
- "'encoding' argument not specified", 1);
- }
- }
- else if (strcmp(encoding, "locale") == 0) {
- encoding = NULL;
- }
-
if (encoding == NULL) {
/* Try os.device_encoding(fileno) */
PyObject *fileno;