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: Document the fact that constructing OSError with erron returns subclass if possible
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: 23391 Superseder:
Assigned To: docs@python Nosy List: asvetlov, docs@python, martin.panter, serhiy.storchaka
Priority: normal Keywords: easy

Created on 2012-12-26 11:35 by asvetlov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg178204 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-12-26 11:35
I mean adding examples for constructions like this:

>>> OSError(errno.ENOENT, 'error msg')
FileNotFoundError(2, 'error msg')
msg178205 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-26 11:44
However

>>> OSError(errno.ENOENT)
OSError(2,)
>>> OSError(errno.ENOENT, 'error msg', 'filename', 'spam')
OSError(2, 'error msg', 'filename', 'spam')
msg253169 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-19 04:09
My proposed patch at Issue 23391 addresses this
msg253513 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-27 03:56
Hopefully revision cb554248ce54 is good enough to close this. The documentation now says

'''
The constructor often actually returns a subclass of OSError, as described in “OS exceptions” below. The particular subclass depends on the final “errno” value. This behaviour only occurs when constructing OSError directly or via an alias, and is not inherited when subclassing.
'''

Serhiy’s first case does not set the “errno” attribute (by design I assume). In the second case, I suspect the behaviour has changed since 2012, or it depends on the platform. On Windows, the 'spam' argument is meant to become “winerror”, which can override “errno” if it is an integer. 3.6 on Linux:

>>> OSError(errno.ENOENT, 'error msg', 'filename', 'spam')
FileNotFoundError(2, 'error msg')
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60989
2015-10-27 03:56:56martin.pantersetstatus: open -> closed
resolution: fixed
messages: + msg253513

stage: needs patch -> resolved
2015-10-19 04:09:06martin.pantersetnosy: + martin.panter
dependencies: + Documentation of EnvironmentError (OSError) arguments disappeared
messages: + msg253169
2012-12-26 11:44:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg178205

type: enhancement
stage: needs patch
2012-12-26 11:35:12asvetlovcreate