New submission from Richard Oudkerk:

Since WindowsError became an alias of OSError, the error number shown in the 
stringification of an OSError err can either be a windows error code 
(err.winerror) or a posix style error number (err.errno), with no way to tell 
which.

For instance in

  >>> os.read(999, 0)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  OSError: [Errno 9] Bad file descriptor

err.errno == EBADF == 9 and err.winerror == None, but in

  >>> _winapi.ReadFile(999, 0)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  OSError: [Error 6] The handle is invalid

err.errno == EBADF == 9 and err.winerror == ERROR_INVALID_HANDLE == 6.  
(winerror gets priority over errno if it exists.)

With the attached patch the second will be shown as

  >>> _winapi.ReadFile(999, 0)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  OSError: [WinError 6] The handle is invalid
            ^^^

Since this issue only applies to 3.3 and the patch is trivial, it would be nice 
to get this in before 3.3 is released.

----------
files: winerror.patch
keywords: patch
messages: 169153
nosy: pitrou, sbt
priority: normal
severity: normal
status: open
title: OSError.__str__() should distinguish between errno and winerror
Added file: http://bugs.python.org/file27001/winerror.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15784>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to