Eryk Sun <[email protected]> added the comment:
Thanks for working on a PR, Zackery. Note that we can't rely on GetLastError()
in PyErr_SetFromErrnoWithFilenameObjects. It may be called in contexts where
the thread's LastErrorValue is no longer related to the C errno value.
My suggestion in msg272427 was intended for _io_FileIO___init___impl in
Modules/_io/fileio.c. Actually, a more useful change would be to modify this
function to use the CRT _doserrno value [1]. Set _doserrno = 0 prior to calling
_wopen. If it fails, set the exception via
PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, _doserrno,
nameobj). This will improve cases in which several system error codes are
mapped to a single errno value such as ENOENT.
In theory, I like the idea of clarifying the error message for
ERROR_PATH_NOT_FOUND (3) in PyErr_SetExcFromWindowsErrWithFilenameObjects. One
concern I have is that this ignores the localization of the error message just
for this single error code. It could extend the localized message with an
English sentence, but is this too awkward? For example:
El sistema no puede encontrar la ruta especificada. The path may
exceed the maximum allowed length.
[1]:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr?view=vs-2019
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue27729>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com