[issue16785] Document the fact that constructing OSError with erron returns subclass if possible
New submission from Andrew Svetlov: I mean adding examples for constructions like this:
OSError(errno.ENOENT, 'error msg') FileNotFoundError(2, 'error msg')
---------- assignee: docs@python components: Documentation keywords: easy messages: 178204 nosy: asvetlov, docs@python priority: normal severity: normal status: open title: Document the fact that constructing OSError with erron returns subclass if possible versions: Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16785> _______________________________________
Serhiy Storchaka added the comment: However
OSError(errno.ENOENT) OSError(2,) OSError(errno.ENOENT, 'error msg', 'filename', 'spam') OSError(2, 'error msg', 'filename', 'spam')
---------- nosy: +serhiy.storchaka stage: -> needs patch type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16785> _______________________________________
Martin Panter added the comment: My proposed patch at Issue 23391 addresses this ---------- dependencies: +Documentation of EnvironmentError (OSError) arguments disappeared nosy: +martin.panter _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16785> _______________________________________
Martin Panter added the comment: 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')
---------- resolution: -> fixed stage: needs patch -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue16785> _______________________________________
participants (3)
-
Andrew Svetlov
-
Martin Panter
-
Serhiy Storchaka