Skip to content

bpo-30565: Remove PEP 538 warnings #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 6 additions & 51 deletions Lib/test/test_c_locale_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)



Expand All @@ -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": "",
Expand All @@ -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
Expand All @@ -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()

Expand Down
28 changes: 0 additions & 28 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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, "");
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
27 changes: 0 additions & 27 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand Down
17 changes: 0 additions & 17 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 0 additions & 3 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down