In e895de3e7f3cc2f7213b87621cfe9812ea4343f0 / bpo-35813, the deprecated function PyErr_SetFromWindowsErrWithUnicodeFilename() was added in two functions in Modules/_winapi.c. This function was deprecated in 3.3 (and all occurrences of it were removed). Also, if bpo-33407 is accepted, usage of this function will cause compiler warnings. See also bpo-19569.
This was my fault for recommending PyErr_SetFromWindowsErrWithUnicodeFilename without checking the header for deprecation. PyErr_SetFromWindowsErrWithUnicodeFilename is an internal function (added for PEP 277, circa 2.4), which was never documented in the C API. I don't follow why Serhiy deprecated it in 2016, since at the same time he updated it to use PyUnicode_FromWideChar instead of PyUnicode_FromUnicode. I see no fundamental difference in terms of resource usage between it and PyErr_SetExcFromWindowsErrWithFilename, which instead calls PyUnicode_DecodeFSDefault. In this case, the section object (file mapping) name is useful information in the exception. If the deprecation isn't lifted, it puts the onus on us to implement this functionality -- i.e. PyUnicode_FromWideChar, PyErr_SetExcFromWindowsErrWithFilenameObjects, Py_XDECREF. Or maybe add a new PyErr_SetExcFromWindowsErrWithWideCharFilename function that takes a `const wchar_t *` string, and document it in the C API.
The PR for bpo-33407 has been merged, so two warnings are now emitted in Modules/_winapi.c. I think it would be best to replace the two calls with PyErr_SetFromWindowsErr(0) (for now). Eryk, I think a discussion on python-dev would be necessary for something like PyErr_SetExcFromWindowsErrWithWideCharFilename().
> I think it would be best to replace the two calls with > PyErr_SetFromWindowsErr(0) (for now). For now it can at least be implemented inline. For example: if (handle == NULL) { PyObject *temp = name ? PyUnicode_FromWideChar(name, -1) : NULL; PyErr_SetExcFromWindowsErrWithFilenameObjects(PyExc_OSError, 0, temp, NULL); Py_XDECREF(temp); handle = INVALID_HANDLE_VALUE; } I think undeprecating the two PyErr_ functions with a modified signature in 3.8 is okay since they were never in the documented API, never in the stable (limited) API, and Py_UNICODE has been a typedef for wchar_t since 3.3.