This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: OSError.__str__() should distinguish between errno and winerror
Type: Stage:
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: sbt Nosy List: georg.brandl, pitrou, python-dev, sbt
Priority: normal Keywords: patch

Created on 2012-08-25 18:44 by sbt, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
winerror.patch sbt, 2012-08-25 19:06 review
Messages (9)
msg169153 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-08-25 18:44
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.
msg169224 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-27 21:30
I originally kept it that way to minimize disruption with 3.2, but I agree it's a welcome change. As for acceptance in 3.3, Georg will have to decide.
msg169226 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-08-27 21:36
Uh, currently it's "Errno" or "Error", so there is a way to tell which.

I'll leave to Antoine to decide what to do here; it's not like changing it a big deal.

"WinError" looks kind of ugly to me though.
msg169227 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-27 22:13
Well, "Error" and "Errno" are rather hard to distinguish, and the difference isn't obvious either, so Richard's patch is a good improvement IMHO.
msg169241 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-08-28 00:33
> Well, "Error" and "Errno" are rather hard to distinguish

Embarrassingly, I did not even notice the was a difference.
msg169291 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-08-28 19:22
New changeset 2e587b9bae35 by Richard Oudkerk in branch 'default':
Issue #15784: Modify OSError.__str__() to better distinguish between
http://hg.python.org/cpython/rev/2e587b9bae35
msg169366 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-08-29 11:25
The changeset is 2e587b9bae35.

Georg, could you copy it to your release branch please.
msg170029 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-09-08 05:49
Done in 4e941113e4fa.
msg170089 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-09-09 09:18
New changeset 4e941113e4fa by Richard Oudkerk in branch 'default':
Issue #15784: Modify OSError.__str__() to better distinguish between
http://hg.python.org/cpython/rev/4e941113e4fa
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 59988
2012-09-09 09:18:56python-devsetmessages: + msg170089
2012-09-08 05:49:25georg.brandlsetstatus: open -> closed

messages: + msg170029
2012-08-29 11:25:39sbtsetmessages: + msg169366
2012-08-28 19:22:47python-devsetnosy: + python-dev
messages: + msg169291
2012-08-28 00:33:37sbtsetmessages: + msg169241
2012-08-27 22:13:54pitrousetassignee: sbt
messages: + msg169227
components: + Interpreter Core
versions: + Python 3.3
2012-08-27 21:36:48georg.brandlsetmessages: + msg169226
2012-08-27 21:30:10pitrousetmessages: + msg169224
2012-08-27 21:29:09pitrousetnosy: + georg.brandl
2012-08-25 19:06:30sbtsetfiles: - winerror.patch
2012-08-25 19:06:26sbtsetfiles: + winerror.patch
2012-08-25 18:44:37sbtcreate