--- Modules/main.c +++ Modules/main.c @@ -575,6 +575,10 @@ PySys_AddWarnOptionUnicode(PyList_GET_ITEM(warning_options, i)); } } + if (Py_BytesWarningFlag > 1) + PySys_AddWarnOption(L"error::BytesWarning"); + else if (Py_BytesWarningFlag) + PySys_AddWarnOption(L"default::BytesWarning"); if (command == NULL && module == NULL && _PyOS_optind < argc && wcscmp(argv[_PyOS_optind], L"-") != 0) --- Python/_warnings.c +++ Python/_warnings.c @@ -981,10 +981,10 @@ static PyObject * init_filters(void) { - PyObject *filters = PyList_New(5); + PyObject *filters = PyList_New(4); unsigned int pos = 0; /* Post-incremented in each use. */ unsigned int x; - const char *bytes_action, *resource_action; + const char *resource_action; if (filters == NULL) return NULL; @@ -995,14 +995,6 @@ create_filter(PyExc_PendingDeprecationWarning, "ignore")); PyList_SET_ITEM(filters, pos++, create_filter(PyExc_ImportWarning, "ignore")); - if (Py_BytesWarningFlag > 1) - bytes_action = "error"; - else if (Py_BytesWarningFlag) - bytes_action = "default"; - else - bytes_action = "ignore"; - PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning, - bytes_action)); /* resource usage warnings are enabled by default in pydebug mode */ #ifdef Py_DEBUG resource_action = "always";