Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01fd26c

Browse files
committed
Improve description of PEP 3151
1 parent 767c0a8 commit 01fd26c

1 file changed

Lines changed: 38 additions & 33 deletions

File tree

Doc/whatsnew/3.3.rst

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,40 +113,44 @@ PEP 3151: Reworking the OS and IO exception hierarchy
113113
=====================================================
114114

115115
:pep:`3151` - Reworking the OS and IO exception hierarchy
116-
PEP written and implemented by Antoine Pitrou.
117-
118-
New subclasses of :exc:`OSError` exceptions:
119-
120-
* :exc:`BlockingIOError`
121-
* :exc:`ChildProcessError`
122-
* :exc:`ConnectionError`
123-
124-
* :exc:`BrokenPipeError`
125-
* :exc:`ConnectionAbortedError`
126-
* :exc:`ConnectionRefusedError`
127-
* :exc:`ConnectionResetError`
128-
129-
* :exc:`FileExistsError`
130-
* :exc:`FileNotFoundError`
131-
* :exc:`InterruptedError`
132-
* :exc:`IsADirectoryError`
133-
* :exc:`NotADirectoryError`
134-
* :exc:`PermissionError`
135-
* :exc:`ProcessLookupError`
136-
* :exc:`TimeoutError`
137-
138-
The following exceptions have been merged into :exc:`OSError`:
139-
140-
* :exc:`EnvironmentError`
141-
* :exc:`IOError`
142-
* :exc:`WindowsError`
143-
* :exc:`VMSError`
144-
* :exc:`socket.error`
145-
* :exc:`select.error`
146-
* :exc:`mmap.error`
116+
PEP written and implemented by Antoine Pitrou.
117+
118+
The hierarchy of exceptions raised by operating system errors is now both
119+
simplified and finer-grained.
120+
121+
You don't have to worry anymore about choosing the appropriate exception
122+
type between :exc:`OSError`, :exc:`IOError`, :exc:`EnvironmentError`,
123+
:exc:`WindowsError`, :exc:`mmap.error`, :exc:`socket.error` or
124+
:exc:`select.error`. All these exception types are now only one:
125+
:exc:`OSError`. The other names are kept as aliases for compatibility
126+
reasons.
127+
128+
Also, it is now easier to catch a specific error condition. Instead of
129+
inspecting the ``errno`` attribute (or ``args[0]``) for a particular
130+
constant from the :mod:`errno` module, you can catch the adequate
131+
:exc:`OSError` subclass. The available subclasses are the following:
132+
133+
* :exc:`BlockingIOError`
134+
* :exc:`ChildProcessError`
135+
* :exc:`ConnectionError`
136+
* :exc:`FileExistsError`
137+
* :exc:`FileNotFoundError`
138+
* :exc:`InterruptedError`
139+
* :exc:`IsADirectoryError`
140+
* :exc:`NotADirectoryError`
141+
* :exc:`PermissionError`
142+
* :exc:`ProcessLookupError`
143+
* :exc:`TimeoutError`
144+
145+
And the :exc:`ConnectionError` itself has finer-grained subclasses:
146+
147+
* :exc:`BrokenPipeError`
148+
* :exc:`ConnectionAbortedError`
149+
* :exc:`ConnectionRefusedError`
150+
* :exc:`ConnectionResetError`
147151

148152
Thanks to the new exceptions, common usages of the :mod:`errno` can now be
149-
avoided. For example, the following code written for Python 3.2: ::
153+
avoided. For example, the following code written for Python 3.2::
150154

151155
from errno import ENOENT, EACCES, EPERM
152156

@@ -161,7 +165,8 @@ avoided. For example, the following code written for Python 3.2: ::
161165
else:
162166
raise
163167

164-
can now be written without the :mod:`errno` import: ::
168+
can now be written without the :mod:`errno` import and without manual
169+
inspection of exception attributes::
165170

166171
try:
167172
with open("document.txt") as f:

0 commit comments

Comments
 (0)