[Python-checkins] peps: Mention the interesting idea of modifiying IOError.__new__
antoine.pitrou
python-checkins at python.org
Thu May 12 19:31:46 CEST 2011
http://hg.python.org/peps/rev/0502a584fd63
changeset: 3879:0502a584fd63
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu May 12 19:31:43 2011 +0200
summary:
Mention the interesting idea of modifiying IOError.__new__
(instead of the PyErr_SetFromErrno functions)
files:
pep-3151.txt | 21 +++++++++------------
1 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/pep-3151.txt b/pep-3151.txt
--- a/pep-3151.txt
+++ b/pep-3151.txt
@@ -440,22 +440,19 @@
Since it is proposed that the subclasses are raised based purely on the
value of ``errno``, little or no changes should be required in extension
-modules (either standard or third-party). As long as they use the
-``PyErr_SetFromErrno()`` family of functions (or the
-``PyErr_SetFromWindowsErr()`` family of functions under Windows), they
-should automatically benefit from the new, finer-grained exception classes.
+modules (either standard or third-party).
-Library modules written in Python, though, will have to be adapted where
-they currently use the following idiom (seen in ``Lib/tempfile.py``)::
+The first possibility is to adapt the ``PyErr_SetFromErrno()`` family
+of functions (``PyErr_SetFromWindowsErr()`` under Windows) to raise the
+appropriate ``IOError`` subclass. This wouldn't cover, however, Python
+code raising IOError directly, using the following idiom (seen in
+``Lib/tempfile.py``)::
raise IOError(_errno.EEXIST, "No usable temporary file name found")
-Fortunately, such Python code is quite rare since raising OSError or IOError
-with an errno value normally happens when interfacing with system calls,
-which is usually done in C extensions.
-
-If there is popular demand, the subroutine choosing an exception type based
-on the errno value could be exposed for use in pure Python.
+A second possibility, suggested by Marc-Andre Lemburg, is to adapt
+``IOError.__new__`` to instantiate the appropriate subclass. This would
+have the benefit of also covering Python code such as the above.
Possible objections
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list