Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
bpo-43510: Implement PEP 597 opt-in EncodingWarning.#19481
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
a3c014b050bd1b939f4a03c997774016278c5c556cd9a08c2772648e1a8e30520966cd2b80f42760308ca95dff231fb411096a0a399fc9386fdbcbc3f362bc674feffd9d850f16463ea412d633ee883d16a15e2a5d474b4c17016f03f971c9d26b7a60e74cfa505b5fcbe22e2a9f9f043bea88fd260a4c049a269018ba643a9623e737059e6a6221154c7dc65b2830b14f2a6e06e2a3227d49d280f46446ad0e7f73b27f1c149d654eb7655e3bce76c089fd7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
sys.flags.encoding_warning -> warn_default_encoding-X warn_encoding -> warn_default_encodingPYTHONWARNENCODING -> PYTHONWARNDEFAULTENCODING
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -583,6 +583,13 @@ PyConfig | ||
| Default: ``0``. | ||
| .. c:member:: int warn_default_encoding | ||
| If equals to 1, emit a ``EncodingWarning`` when ``TextIOWrapper`` | ||
| used its default encoding. See :pep:`597` for detail. | ||
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .. versionadded:: 3.10 | ||
| .. c:member:: wchar_t* check_hash_pycs_mode | ||
| Control the validation behavior of hash-based ``.pyc`` files: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -102,15 +102,15 @@ typedef struct { | ||
| int isolated; /* -I option */ | ||
| int use_environment; /* -E option */ | ||
| int dev_mode; /* -X dev and PYTHONDEVMODE */ | ||
| intwarn_default_encoding; /* -Xwarn_default_encoding andPYTHONWARNDEFAULTENCODING */ | ||
| } _PyPreCmdline; | ||
| #define _PyPreCmdline_INIT \ | ||
| (_PyPreCmdline){ \ | ||
| .use_environment = -1, \ | ||
| .isolated = -1, \ | ||
| .dev_mode = -1, \ | ||
| .warn_default_encoding = -1} | ||
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| /* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */ | ||
| extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,18 +48,16 @@ def text_encoding(encoding, stacklevel=1): | ||
| Otherwise, return the default text encoding (i.e. "locale"). | ||
| This function emits EncodingWarning if *encoding* is None and | ||
| sys.flags.warn_default_encoding is true. | ||
| This function can be used in APIs having encoding=None option. | ||
| But please consider encoding="utf-8" for new APIs. | ||
| """ | ||
| if encoding is None: | ||
| if sys.flags.warn_default_encoding: | ||
| import warnings | ||
| warnings.warn("'encoding' option is not specified.", | ||
| EncodingWarning, stacklevel + 2) | ||
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| encoding = "locale" | ||
| return encoding | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1125,7 +1125,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | ||
| if (encoding == NULL) { | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) { | ||
| PyErr_WarnEx(PyExc_EncodingWarning, | ||
| "'encoding' option is omitted", 1); | ||
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -94,7 +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\ | ||
| -Xwarn_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\ | ||
| @@ -131,7 +131,7 @@ static const char usage_6[] = | ||
| " 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" | ||
| "PYTHONWARNDEFAULTENCODING: enable opt-in EncodingWarning for 'encoding=None'.\n"; | ||
| #if defined(MS_WINDOWS) | ||
| # define PYTHONHOMEHELP "<prefix>\\python{major}{minor}" | ||
| @@ -602,7 +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); | ||
| @@ -701,7 +701,7 @@ _PyConfig_InitCompatConfig(PyConfig *config) | ||
| config->parse_argv = 0; | ||
| config->site_import = -1; | ||
| config->bytes_warning = -1; | ||
| config->warn_default_encoding = -1; | ||
methane marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| config->inspect = -1; | ||
| config->interactive = -1; | ||
| config->optimization_level = -1; | ||
| @@ -732,7 +732,7 @@ config_init_defaults(PyConfig *config) | ||
| config->use_environment = 1; | ||
| config->site_import = 1; | ||
| config->bytes_warning = 0; | ||
| config->warn_default_encoding = 0; | ||
| config->inspect = 0; | ||
| config->interactive = 0; | ||
| config->optimization_level = 0; | ||
| @@ -911,7 +911,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); | ||
| @@ -1013,7 +1013,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); | ||
| @@ -1278,7 +1278,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); | ||
| @@ -2144,8 +2144,8 @@ config_read(PyConfig *config, int compute_path_config) | ||
| config->parse_argv = 2; | ||
| } | ||
| if (config->warn_default_encoding < 0) { | ||
| config->warn_default_encoding = 0; | ||
| } | ||
| return _PyStatus_OK(); | ||