Skip to content

Commit 62ab10a

Browse files
committed
Replace mentions of IOError
1 parent 5d6fbe8 commit 62ab10a

17 files changed

Lines changed: 85 additions & 39 deletions

Doc/library/atexit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ making an explicit call into this module at termination. ::
6969
try:
7070
with open("/tmp/counter") as infile:
7171
_count = int(infile.read())
72-
except IOError:
72+
except FileNotFoundError:
7373
_count = 0
7474

7575
def incrcounter(n):

Doc/library/fcntl.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ argument. This can be an integer file descriptor, such as returned by
1919
``sys.stdin.fileno()``, or a :class:`io.IOBase` object, such as ``sys.stdin``
2020
itself, which provides a :meth:`fileno` that returns a genuine file descriptor.
2121

22+
.. versionchanged:: 3.3
23+
Operations in this module used to raise a :exc:`IOError` where they now
24+
raise a :exc:`OSError`.
25+
26+
2227
The module defines the following functions:
2328

2429

@@ -40,7 +45,7 @@ The module defines the following functions:
4045
larger than 1024 bytes, this is most likely to result in a segmentation
4146
violation or a more subtle data corruption.
4247

43-
If the :c:func:`fcntl` fails, an :exc:`IOError` is raised.
48+
If the :c:func:`fcntl` fails, an :exc:`OSError` is raised.
4449

4550

4651
.. function:: ioctl(fd, op[, arg[, mutate_flag]])
@@ -107,7 +112,7 @@ The module defines the following functions:
107112
When *operation* is :const:`LOCK_SH` or :const:`LOCK_EX`, it can also be
108113
bitwise ORed with :const:`LOCK_NB` to avoid blocking on lock acquisition.
109114
If :const:`LOCK_NB` is used and the lock cannot be acquired, an
110-
:exc:`IOError` will be raised and the exception will have an *errno*
115+
:exc:`OSError` will be raised and the exception will have an *errno*
111116
attribute set to :const:`EACCES` or :const:`EAGAIN` (depending on the
112117
operating system; for portability, check for both values). On at least some
113118
systems, :const:`LOCK_EX` can only be used if the file descriptor refers to a

Doc/library/functions.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ are always available. They are listed here in alphabetical order.
783783
.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)
784784

785785
Open *file* and return a corresponding stream. If the file cannot be opened,
786-
an :exc:`IOError` is raised.
786+
an :exc:`OSError` is raised.
787787

788788
*file* is either a string or bytes object giving the pathname (absolute or
789789
relative to the current working directory) of the file to be opened or
@@ -912,6 +912,9 @@ are always available. They are listed here in alphabetical order.
912912
(where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
913913
and :mod:`shutil`.
914914

915+
.. versionchanged:: 3.3
916+
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
917+
915918

916919
.. XXX works for bytes too, but should it?
917920
.. function:: ord(c)

Doc/library/gettext.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,13 @@ class can also install themselves in the built-in namespace as the function
185185
translation object from the cache; the actual instance data is still shared with
186186
the cache.
187187

188-
If no :file:`.mo` file is found, this function raises :exc:`IOError` if
188+
If no :file:`.mo` file is found, this function raises :exc:`OSError` if
189189
*fallback* is false (which is the default), and returns a
190190
:class:`NullTranslations` instance if *fallback* is true.
191191

192+
.. versionchanged:: 3.3
193+
:exc:`IOError` used to be raised instead of :exc:`OSError`.
194+
192195

193196
.. function:: install(domain, localedir=None, codeset=None, names=None)
194197

@@ -342,7 +345,7 @@ The entire set of key/value pairs are placed into a dictionary and set as the
342345

343346
If the :file:`.mo` file's magic number is invalid, or if other problems occur
344347
while reading the file, instantiating a :class:`GNUTranslations` class can raise
345-
:exc:`IOError`.
348+
:exc:`OSError`.
346349

347350
The following methods are overridden from the base class implementation:
348351

Doc/library/http.cookiejar.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ The module defines the following exception:
4040
.. exception:: LoadError
4141

4242
Instances of :class:`FileCookieJar` raise this exception on failure to load
43-
cookies from a file. :exc:`LoadError` is a subclass of :exc:`IOError`.
43+
cookies from a file. :exc:`LoadError` is a subclass of :exc:`OSError`.
44+
45+
.. versionchanged:: 3.3
46+
LoadError was made a subclass of :exc:`OSError` instead of
47+
:exc:`IOError`.
4448

4549

4650
The following classes are provided:
@@ -257,9 +261,12 @@ contained :class:`Cookie` objects.
257261
Arguments are as for :meth:`save`.
258262

259263
The named file must be in the format understood by the class, or
260-
:exc:`LoadError` will be raised. Also, :exc:`IOError` may be raised, for
264+
:exc:`LoadError` will be raised. Also, :exc:`OSError` may be raised, for
261265
example if the file does not exist.
262266

267+
.. versionchanged:: 3.3
268+
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
269+
263270

264271
.. method:: FileCookieJar.revert(filename=None, ignore_discard=False, ignore_expires=False)
265272

Doc/library/http.server.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ of which this module provides three different variants:
318318
response if the :func:`listdir` fails.
319319

320320
If the request was mapped to a file, it is opened and the contents are
321-
returned. Any :exc:`IOError` exception in opening the requested file is
321+
returned. Any :exc:`OSError` exception in opening the requested file is
322322
mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
323323
type is guessed by calling the :meth:`guess_type` method, which in turn
324324
uses the *extensions_map* variable.

Doc/library/inspect.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,25 @@ Retrieving source code
355355
argument may be a module, class, method, function, traceback, frame, or code
356356
object. The source code is returned as a list of the lines corresponding to the
357357
object and the line number indicates where in the original source file the first
358-
line of code was found. An :exc:`IOError` is raised if the source code cannot
358+
line of code was found. An :exc:`OSError` is raised if the source code cannot
359359
be retrieved.
360360

361+
.. versionchanged:: 3.3
362+
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
363+
former.
364+
361365

362366
.. function:: getsource(object)
363367

364368
Return the text of the source code for an object. The argument may be a module,
365369
class, method, function, traceback, frame, or code object. The source code is
366-
returned as a single string. An :exc:`IOError` is raised if the source code
370+
returned as a single string. An :exc:`OSError` is raised if the source code
367371
cannot be retrieved.
368372

373+
.. versionchanged:: 3.3
374+
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
375+
former.
376+
369377

370378
.. function:: cleandoc(doc)
371379

Doc/library/msvcrt.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ api. The normal API deals only with ASCII characters and is of limited use
2020
for internationalized applications. The wide char API should be used where
2121
ever possible
2222

23+
.. versionchanged:: 3.3
24+
Operations in this module now raise :exc:`OSError` where :exc:`IOError`
25+
was raised.
26+
27+
2328
.. _msvcrt-files:
2429

2530
File Operations
@@ -29,7 +34,7 @@ File Operations
2934
.. function:: locking(fd, mode, nbytes)
3035

3136
Lock part of a file based on file descriptor *fd* from the C runtime. Raises
32-
:exc:`IOError` on failure. The locked region of the file extends from the
37+
:exc:`OSError` on failure. The locked region of the file extends from the
3338
current file position for *nbytes* bytes, and may continue beyond the end of the
3439
file. *mode* must be one of the :const:`LK_\*` constants listed below. Multiple
3540
regions in a file may be locked at the same time, but may not overlap. Adjacent
@@ -41,13 +46,13 @@ File Operations
4146

4247
Locks the specified bytes. If the bytes cannot be locked, the program
4348
immediately tries again after 1 second. If, after 10 attempts, the bytes cannot
44-
be locked, :exc:`IOError` is raised.
49+
be locked, :exc:`OSError` is raised.
4550

4651

4752
.. data:: LK_NBLCK
4853
LK_NBRLCK
4954

50-
Locks the specified bytes. If the bytes cannot be locked, :exc:`IOError` is
55+
Locks the specified bytes. If the bytes cannot be locked, :exc:`OSError` is
5156
raised.
5257

5358

@@ -73,7 +78,7 @@ File Operations
7378

7479
.. function:: get_osfhandle(fd)
7580

76-
Return the file handle for the file descriptor *fd*. Raises :exc:`IOError` if
81+
Return the file handle for the file descriptor *fd*. Raises :exc:`OSError` if
7782
*fd* is not recognized.
7883

7984

@@ -144,4 +149,4 @@ Other Functions
144149
.. function:: heapmin()
145150

146151
Force the :c:func:`malloc` heap to clean itself up and return unused blocks to
147-
the operating system. On failure, this raises :exc:`IOError`.
152+
the operating system. On failure, this raises :exc:`OSError`.

Doc/library/multiprocessing.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,14 @@ Connection objects usually created using :func:`Pipe` -- see also
784784
to receive and the other end has closed.
785785

786786
If *maxlength* is specified and the message is longer than *maxlength*
787-
then :exc:`IOError` is raised and the connection will no longer be
787+
then :exc:`OSError` is raised and the connection will no longer be
788788
readable.
789789

790+
.. versionchanged:: 3.3
791+
This function used to raise a :exc:`IOError`, which is now an
792+
alias of :exc:`OSError`.
793+
794+
790795
.. method:: recv_bytes_into(buffer[, offset])
791796

792797
Read into *buffer* a complete message of byte data sent from the other end

Doc/library/os.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,11 +1426,8 @@ Files and Directories
14261426

14271427
try:
14281428
fp = open("myfile")
1429-
except IOError as e:
1430-
if e.errno == errno.EACCESS:
1431-
return "some default data"
1432-
# Not a permission error.
1433-
raise
1429+
except PermissionError:
1430+
return "some default data"
14341431
else:
14351432
with fp:
14361433
return fp.read()

0 commit comments

Comments
 (0)