summaryrefslogtreecommitdiffstats
path: root/Python/initconfig.c
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2021-03-29 03:28:14 (GMT)
committerGitHub <noreply@github.com>2021-03-29 03:28:14 (GMT)
commit4827483f47906fecee6b5d9097df2a69a293a85c (patch)
treec4d7e34163e9583c06003d5335d020ce27aa4559 /Python/initconfig.c
parent261a452a1300eeeae1428ffd6e6623329c085e2c (diff)
downloadcpython-4827483f47906fecee6b5d9097df2a69a293a85c.zip
cpython-4827483f47906fecee6b5d9097df2a69a293a85c.tar.gz
cpython-4827483f47906fecee6b5d9097df2a69a293a85c.tar.bz2
bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)
See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
Diffstat (limited to 'Python/initconfig.c')
-rw-r--r--Python/initconfig.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c
index 7886d09..27ae48d 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -94,6 +94,7 @@ static const char usage_3[] = "\
otherwise activate automatically)\n\
-X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the\n\
given directory instead of to the code tree\n\
+ -X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'\n\
\n\
--check-hash-based-pycs always|default|never:\n\
control how Python invalidates hash-based .pyc files\n\
@@ -129,7 +130,8 @@ static const char usage_6[] =
"PYTHONBREAKPOINT: if this variable is set to 0, it disables the default\n"
" debugger. It can be set to the callable of your debugger of choice.\n"
"PYTHONDEVMODE: enable the development mode.\n"
-"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n";
+"PYTHONPYCACHEPREFIX: root directory for bytecode cache (pyc) files.\n"
+"PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n";
#if defined(MS_WINDOWS)
# define PYTHONHOMEHELP "<prefix>\\python{major}{minor}"
@@ -600,6 +602,7 @@ config_check_consistency(const PyConfig *config)
assert(config->malloc_stats >= 0);
assert(config->site_import >= 0);
assert(config->bytes_warning >= 0);
+ assert(config->warn_default_encoding >= 0);
assert(config->inspect >= 0);
assert(config->interactive >= 0);
assert(config->optimization_level >= 0);
@@ -698,6 +701,7 @@ _PyConfig_InitCompatConfig(PyConfig *config)
config->parse_argv = 0;
config->site_import = -1;
config->bytes_warning = -1;
+ config->warn_default_encoding = 0;
config->inspect = -1;
config->interactive = -1;
config->optimization_level = -1;
@@ -906,6 +910,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
COPY_ATTR(site_import);
COPY_ATTR(bytes_warning);
+ COPY_ATTR(warn_default_encoding);
COPY_ATTR(inspect);
COPY_ATTR(interactive);
COPY_ATTR(optimization_level);
@@ -1007,6 +1012,7 @@ _PyConfig_AsDict(const PyConfig *config)
SET_ITEM_WSTR(platlibdir);
SET_ITEM_INT(site_import);
SET_ITEM_INT(bytes_warning);
+ SET_ITEM_INT(warn_default_encoding);
SET_ITEM_INT(inspect);
SET_ITEM_INT(interactive);
SET_ITEM_INT(optimization_level);
@@ -1271,6 +1277,7 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
GET_WSTRLIST(warnoptions);
GET_UINT(site_import);
GET_UINT(bytes_warning);
+ GET_UINT(warn_default_encoding);
GET_UINT(inspect);
GET_UINT(interactive);
GET_UINT(optimization_level);