[Python-ideas] PEP 3151 - Reworking the OS and IO exception hierarchy (again)

Antoine Pitrou solipsis at pitrou.net
Thu Nov 11 14:08:30 CET 2010

On Thu, 11 Nov 2010 22:03:36 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> This issue is addressed directly in the PEP by the "Compatibility
> Strategy" section. Code which checks errno will not suddenly start
> catching additional exceptions due to the merger of IOError and
> OSError.
> However, I agree with you that the PEP would benefit from keeping
> socket.error, select.error and mmap.error as separate IOError
> subclasses. Existing code may legitimately be catching those in try
> blocks that include other unrelated operations that may raise IOError.

Most socket I/O errors use different errnos (socket-specific errnos such
as ECONNRESET, etc.), so merging the exception classes wouldn't change
anything for careful code which checks the errno.

As for mmap.error, I think it's a design mistake in the first place,
since mmap'ed files are not consistently different from normal files.

As for select.error, the way the select module itself is generally
inconsistent in which exceptions it raises also makes me think it is a
design or implementation bug. The fact that it doesn't even inherit
EnvinromentError reinforces that feeling.

More fundamentally, the effort to create a detailed IO exception
hierarchy is much less useful if we keep islands such as socket.error,
mmap.error, since those errors won't benefit. The PEP only achieves
maximum usefulnesss if it can leverage a single IO exception base

That said, it is obvious that this PEP can raise compatibility concerns
for uncaring code (code which is already poorly written in the first
place). There's no way to reorganize the exception hierarchy without
risking such issues. Actually, even without reorganizing the exception
hierarchy, it often happens that we casually change the exception type
raised by a given function, because we think the old behaviour was
mistaken. Nobody apparently blames us for doing that (perhaps they
are not reading python-checkins carefully enough :-)).

So, as a data point, carefully merging the exception classes (all of
OSError, IOError, EnvinronmentError, WindowsError, VMSError,
socket.error, mmap.error and select.error) doesn't produce any error in
the regression test suite. You can look at the SVN branch named
"pep-3151" for that.



More information about the Python-ideas mailing list