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 2015-10-27 03:56 by martin.panter. 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
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