Skip to content

Commit cf21504

Browse files
authored
bpo-34485: Emit C locale coercion warning later (pythonGH-9002)
PYTHONCOERCELOCALE=warn warning is now emitted later and written into sys.stderr, rather than being written into the C stderr stream.
1 parent 3d4226a commit cf21504

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Python/pylifecycle.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,8 @@ static const char *_C_LOCALE_WARNING =
301301
static void
302302
_emit_stderr_warning_for_legacy_locale(const _PyCoreConfig *core_config)
303303
{
304-
if (core_config->coerce_c_locale_warn) {
305-
if (_Py_LegacyLocaleDetected()) {
306-
fprintf(stderr, "%s", _C_LOCALE_WARNING);
307-
}
304+
if (core_config->coerce_c_locale_warn && _Py_LegacyLocaleDetected()) {
305+
PySys_FormatStderr("%s", _C_LOCALE_WARNING);
308306
}
309307
}
310308

@@ -567,10 +565,6 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p,
567565
*/
568566
_PyRuntime.finalizing = NULL;
569567

570-
#ifndef MS_WINDOWS
571-
_emit_stderr_warning_for_legacy_locale(core_config);
572-
#endif
573-
574568
err = _Py_HashRandomization_Init(core_config);
575569
if (_Py_INIT_FAILED(err)) {
576570
return err;
@@ -867,6 +861,11 @@ _Py_InitializeMainInterpreter(PyInterpreterState *interp,
867861
return err;
868862
}
869863
}
864+
865+
#ifndef MS_WINDOWS
866+
_emit_stderr_warning_for_legacy_locale(core_config);
867+
#endif
868+
870869
return _Py_INIT_OK();
871870
}
872871

0 commit comments

Comments
 (0)