From 1a81aeb671790a6f765f974ad16d862535e9e83a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 14 Jun 2017 16:18:20 +0200 Subject: [PATCH] bpo-30565: Remove PEP 538 warnings Writing warnings to stderr causes many test failures in the Python test suite, warning which could only be disabled when building Python but not at runtime. Remove also --with(out)-c-locale-warning option of configure and PY_WARN_ON_C_LOCALE define. --- Lib/test/test_c_locale_coercion.py | 57 ++++-------------------------- Python/pylifecycle.c | 28 --------------- configure | 27 -------------- configure.ac | 17 --------- pyconfig.h.in | 3 -- 5 files changed, 6 insertions(+), 126 deletions(-) diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py index 0d322363176054..d39f56660c574b 100644 --- a/Lib/test/test_c_locale_coercion.py +++ b/Lib/test/test_c_locale_coercion.py @@ -25,8 +25,7 @@ # * Windows when PYTHONLEGACYWINDOWSFSENCODING is set # * AIX and any other platforms that use latin-1 in the C locale -# In order to get the warning messages to match up as expected, the candidate -# order here must much the target locale order in Python/pylifecycle.c +# Use the target locale order of Python/pylifecycle.c _C_UTF8_LOCALES = ("C.UTF-8", "C.utf8", "UTF-8") # There's no reliable cross-platform way of checking locale alias @@ -107,8 +106,7 @@ class _ChildProcessEncodingTestCase(unittest.TestCase): def _check_child_encoding_details(self, env_vars, - expected_fsencoding, - expected_warning): + expected_fsencoding): """Check the C locale handling for the given process environment Parameters: @@ -122,37 +120,7 @@ def _check_child_encoding_details(self, self.assertEqual(encoding_details, EncodingDetails.get_expected_details( expected_fsencoding)) - self.assertEqual(stderr_lines, expected_warning) - -# Details of the shared library warning emitted at runtime -LIBRARY_C_LOCALE_WARNING = ( - "Python runtime initialized with LC_CTYPE=C (a locale with default ASCII " - "encoding), which may cause Unicode compatibility problems. Using C.UTF-8, " - "C.utf8, or UTF-8 (if available) as alternative Unicode-compatible " - "locales is recommended." -) - -@unittest.skipUnless(sysconfig.get_config_var("PY_WARN_ON_C_LOCALE"), - "C locale runtime warning disabled at build time") -class LocaleWarningTests(_ChildProcessEncodingTestCase): - # Test warning emitted when running in the C locale - - def test_library_c_locale_warning(self): - self.maxDiff = None - for locale_to_set in ("C", "POSIX", "invalid.ascii"): - var_dict = { - "LC_ALL": locale_to_set - } - with self.subTest(forced_locale=locale_to_set): - self._check_child_encoding_details(var_dict, - EXPECTED_C_LOCALE_FSENCODING, - [LIBRARY_C_LOCALE_WARNING]) - -# Details of the CLI locale coercion warning emitted at runtime -CLI_COERCION_WARNING_FMT = ( - "Python detected LC_CTYPE=C: LC_CTYPE coerced to {} (set another locale " - "or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior)." -) + self.assertEqual(stderr_lines, []) AVAILABLE_TARGETS = None @@ -189,7 +157,6 @@ def test_external_target_locale_configuration(self): # is seen when implicitly coercing to that target locale self.maxDiff = None - expected_warning = [] expected_fsencoding = "utf-8" base_var_dict = { @@ -209,8 +176,7 @@ def test_external_target_locale_configuration(self): var_dict = base_var_dict.copy() var_dict[env_var] = locale_to_set self._check_child_encoding_details(var_dict, - expected_fsencoding, - expected_warning) + expected_fsencoding) @@ -230,15 +196,6 @@ def _check_c_locale_coercion(self, expected_fsencoding, coerce_c_locale): str: the value set in the child's environment """ - # Check for expected warning on stderr if C locale is coerced - self.maxDiff = None - - expected_warning = [] - if coerce_c_locale != "0": - # Expect coercion to use the first available locale - warning_msg = CLI_COERCION_WARNING_FMT.format(AVAILABLE_TARGETS[0]) - expected_warning.append(warning_msg) - base_var_dict = { "LANG": "", "LC_CTYPE": "", @@ -254,8 +211,7 @@ def _check_c_locale_coercion(self, expected_fsencoding, coerce_c_locale): if coerce_c_locale is not None: var_dict["PYTHONCOERCECLOCALE"] = coerce_c_locale self._check_child_encoding_details(var_dict, - expected_fsencoding, - expected_warning) + expected_fsencoding) def test_test_PYTHONCOERCECLOCALE_not_set(self): # This should coerce to the first available target locale by default @@ -276,8 +232,7 @@ def test_PYTHONCOERCECLOCALE_set_to_zero(self): def test_main(): test.support.run_unittest( LocaleConfigurationTests, - LocaleCoercionTests, - LocaleWarningTests + LocaleCoercionTests ) test.support.reap_children() diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index b7c98225641176..c738dcd8a43b69 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -401,10 +401,6 @@ get_default_standard_stream_error_handler(void) } #ifdef PY_COERCE_C_LOCALE -static const char *_C_LOCALE_COERCION_WARNING = - "Python detected LC_CTYPE=C: LC_CTYPE coerced to %.20s (set another locale " - "or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior).\n"; - static void _coerce_default_locale_settings(const _LocaleCoercionTarget *target) { @@ -419,7 +415,6 @@ _coerce_default_locale_settings(const _LocaleCoercionTarget *target) "Error setting LC_CTYPE, skipping C locale coercion\n"); return; } - fprintf(stderr, _C_LOCALE_COERCION_WARNING, newloc); /* Reconfigure with the overridden environment variables */ setlocale(LC_ALL, ""); @@ -465,26 +460,6 @@ _Py_CoerceLegacyLocale(void) } -#ifdef PY_WARN_ON_C_LOCALE -static const char *_C_LOCALE_WARNING = - "Python runtime initialized with LC_CTYPE=C (a locale with default ASCII " - "encoding), which may cause Unicode compatibility problems. Using C.UTF-8, " - "C.utf8, or UTF-8 (if available) as alternative Unicode-compatible " - "locales is recommended.\n"; - -static void -_emit_stderr_warning_for_c_locale(void) -{ - const char *coerce_c_locale = getenv("PYTHONCOERCECLOCALE"); - if (coerce_c_locale == NULL || strncmp(coerce_c_locale, "0", 2) != 0) { - if (_Py_LegacyLocaleDetected()) { - fprintf(stderr, "%s", _C_LOCALE_WARNING); - } - } -} -#endif - - /* Global initializations. Can be undone by Py_Finalize(). Don't call this twice without an intervening Py_Finalize() call. @@ -561,9 +536,6 @@ void _Py_InitializeCore(const _PyCoreConfig *config) the locale's charset without having to switch locales. */ setlocale(LC_CTYPE, ""); -#ifdef PY_WARN_ON_C_LOCALE - _emit_stderr_warning_for_c_locale(); -#endif #endif #endif diff --git a/configure b/configure index ec42e08f8961c1..a003332de6cbee 100755 --- a/configure +++ b/configure @@ -835,7 +835,6 @@ enable_ipv6 with_doc_strings with_pymalloc with_c_locale_coercion -with_c_locale_warning with_valgrind with_dtrace with_fpectl @@ -1533,9 +1532,6 @@ Optional Packages: --with(out)-c-locale-coercion disable/enable C locale coercion to a UTF-8 based locale - --with(out)-c-locale-warning - disable/enable locale compatibility warning in the C - locale --with-valgrind Enable Valgrind support --with(out)-dtrace disable/enable DTrace support --with-fpectl enable SIGFPE catching @@ -11078,29 +11074,6 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_c_locale_coercion" >&5 $as_echo "$with_c_locale_coercion" >&6; } -# Check for --with-c-locale-warning -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-c-locale-warning" >&5 -$as_echo_n "checking for --with-c-locale-warning... " >&6; } - -# Check whether --with-c-locale-warning was given. -if test "${with_c_locale_warning+set}" = set; then : - withval=$with_c_locale_warning; -fi - - -if test -z "$with_c_locale_warning" -then - with_c_locale_warning="yes" -fi -if test "$with_c_locale_warning" != "no" -then - -$as_echo "#define PY_WARN_ON_C_LOCALE 1" >>confdefs.h - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_c_locale_warning" >&5 -$as_echo "$with_c_locale_warning" >&6; } - # Check for Valgrind support { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-valgrind" >&5 $as_echo_n "checking for --with-valgrind... " >&6; } diff --git a/configure.ac b/configure.ac index 18b940ab329172..554e2830297941 100644 --- a/configure.ac +++ b/configure.ac @@ -3342,23 +3342,6 @@ then fi AC_MSG_RESULT($with_c_locale_coercion) -# Check for --with-c-locale-warning -AC_MSG_CHECKING(for --with-c-locale-warning) -AC_ARG_WITH(c-locale-warning, - AS_HELP_STRING([--with(out)-c-locale-warning], - [disable/enable locale compatibility warning in the C locale])) - -if test -z "$with_c_locale_warning" -then - with_c_locale_warning="yes" -fi -if test "$with_c_locale_warning" != "no" -then - AC_DEFINE(PY_WARN_ON_C_LOCALE, 1, - [Define to emit a locale compatibility warning in the C locale]) -fi -AC_MSG_RESULT($with_c_locale_warning) - # Check for Valgrind support AC_MSG_CHECKING([for --with-valgrind]) AC_ARG_WITH([valgrind], diff --git a/pyconfig.h.in b/pyconfig.h.in index fa2792b18ad419..201a30824f8ca6 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1253,9 +1253,6 @@ /* Define to printf format modifier for Py_ssize_t */ #undef PY_FORMAT_SIZE_T -/* Define to emit a locale compatibility warning in the C locale */ -#undef PY_WARN_ON_C_LOCALE - /* Define if you want to build an interpreter with many run-time checks. */ #undef Py_DEBUG