Add "Error" at the end of class names.

Propose two new intermediate classes (ConnectionError and FileSystemError)
Add a small diagram.
This commit is contained in:
Antoine Pitrou 2010-09-03 17:07:56 +00:00
parent 592702b5ea
commit 4d8faee55c
1 changed files with 52 additions and 20 deletions

View File

@ -154,7 +154,7 @@ something such as::
try: try:
os.remove(filename) os.remove(filename)
except FileNotFound: except FileNotFoundError:
pass pass
@ -330,44 +330,76 @@ New exception classes
The following tentative list of subclasses, along with a description and The following tentative list of subclasses, along with a description and
the list of errnos mapped to them, is submitted to discussion: the list of errnos mapped to them, is submitted to discussion:
* ``FileAlreadyExists``: trying to create a file or directory which already * ``FileAlreadyExistsError``: trying to create a file or directory which
exists (EEXIST) already exists (EEXIST)
* ``FileNotFound``: for all circumstances where a file and directory is * ``FileNotFoundError``: for all circumstances where a file and directory is
requested but doesn't exist (ENOENT) requested but doesn't exist (ENOENT)
* ``IsADirectory``: file-level operation (open(), os.remove()...) requested * ``IsADirectoryError``: file-level operation (open(), os.remove()...)
on a directory (EISDIR) requested on a directory (EISDIR)
* ``NotADirectory``: directory-level operation requested on something else * ``NotADirectoryError``: directory-level operation requested on something
(ENOTDIR) else (ENOTDIR)
* ``PermissionDenied``: trying to run an operation without the adequate access * ``PermissionError``: trying to run an operation without the adequate access
rights - for example filesystem permissions (EACCESS, optionally EPERM) rights - for example filesystem permissions (EACCESS, EPERM)
* ``BlockingIOError``: an operation would block on an object (e.g. socket) set * ``BlockingIOError``: an operation would block on an object (e.g. socket) set
for non-blocking operation (EAGAIN, EALREADY, EWOULDBLOCK, EINPROGRESS); for non-blocking operation (EAGAIN, EALREADY, EWOULDBLOCK, EINPROGRESS);
this is the existing ``io.BlockingIOError`` with an extended role this is the existing ``io.BlockingIOError`` with an extended role
* ``BadFileDescriptor``: operation on an invalid file descriptor (EBADF); * ``FileDescriptorError``: operation on an invalid file descriptor (EBADF);
the default error message could point out that most causes are that the default error message could point out that most causes are that
an existing file descriptor has been closed an existing file descriptor has been closed
* ``ConnectionAborted``: connection attempt aborted by peer (ECONNABORTED) * ``ConnectionAbortedError``: connection attempt aborted by peer (ECONNABORTED)
* ``ConnectionRefused``: connection reset by peer (ECONNREFUSED) * ``ConnectionRefusedError``: connection reset by peer (ECONNREFUSED)
* ``ConnectionReset``: connection reset by peer (ECONNRESET) * ``ConnectionResetError``: connection reset by peer (ECONNRESET)
* ``TimeoutError``: connection timed out (ECONNTIMEOUT); this could be re-cast * ``TimeoutError``: connection timed out (ECONNTIMEOUT); this can be re-cast
as a generic timeout exception, useful for other types of timeout (for as a generic timeout exception, useful for other types of timeout (for
example in Lock.acquire()) example in Lock.acquire())
This list assumes `Step 1`_ is accepted in full; the exception classes In addition, the following exception class are proposed for inclusion:
described above would all derive from the now unified exception type
IOError. It will need reworking if a partial version of step 1 is accepted * ``ConnectionError``: a base class for ``ConnectionAbortedError``,
instead (again, see appendix A for the current distribution of errnos ``ConnectionRefusedError`` and ``ConnectionResetError``
and exception types).
* ``FileSystemError``: a base class for ``FileAlreadyExistsError``,
``FileNotFoundError``, ``IsADirectoryError`` and ``NotADirectoryError``
The following drawing tries to sum up the proposed additions, along with
the corresponding errno values (where applicable). The root of the
sub-hierarchy (IOError, assuming `Step 1`_ is accepted in full) is not
shown::
+-- BlockingIOError EAGAIN, EALREADY, EWOULDBLOCK, EINPROGRESS
+-- ConnectionError
+-- ConnectionAbortedError ECONNABORTED
+-- ConnectionRefusedError ECONNREFUSED
+-- ConnectionResetError ECONNRESET
+-- FileDescriptorError EBADF
+-- FileSystemError
+-- FileAlreadyExistsError EEXIST
+-- FileNotFoundError ENOENT
+-- IsADirectoryError EISDIR
+-- NotADirectoryError ENOTDIR
+-- PermissionError EACCESS, EPERM
+-- TimeoutError ECONNTIMEOUT
Naming
------
Various naming controversies can arise. One of them is whether all
exception class names should end in "``Error``". In favour is consistency
with the rest of the exception hiearchy, against is concision (especially
with long names such as ``FileAlreadyExistsError``).
Another cosmetic issue is whether ``FileSystemError`` should be spelled
``FilesystemError`` instead.
Exception attributes Exception attributes
-------------------- --------------------