[Python-ideas] PEP-3151 pattern-matching

M.-A. Lemburg mal at egenix.com
Fri Apr 8 10:59:16 CEST 2011


Nick Coghlan wrote:
> On Thu, Apr 7, 2011 at 6:43 PM, M.-A. Lemburg <mal at egenix.com> wrote:
>> The main problem with the PEP is the proposal to flatten existing
>> exception class hierarchies, e.g. making socket.error the same
>> as IOError.
>>
>> This introduces very subtle compatibility problems with code that
>> uses the flattened exception classes in separate except branches, e.g.
>>
>> try:
>>  ...
>> except socket.error:
>>  ...
>> except IOError:
>>  ...
>>
>> With the PEP implemented, the above code would never get
>> to execute the IOError branch and instead divert all error
>> handling to the socket.error branch which may well not be
>> aware of all the extra cases it now has to handle.
>>
>> I think that this part of the PEP should not be accepted.
> 
> I think EnvironmentError, WindowsError, VMSError, OSError, mmap.error
> and select.error should definitely all be merged with IOError, as they
> aren't used consistently enough to make handling them differently
> reliable even in current code.

Their use may be inconsistent in a few places, but those cases
are still well-defined by the implementation, so code relying
on that well-defined behavior will break in subtle ways.

Example:

If code catches select.error (which is only raised for select.select()
and poll_object.poll() calls), because the try...except is expecting
a possible error from the select call used in the try...except
block, it will most likely do the wrong thing for some IOError
raised by a logging file I/O call in that same block.

Moreover, catching the exception at the wrong level, will
prevent the IOError from bubbling up the call chain and can
effectively mask potential errors at lower levels.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 08 2011)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/



More information about the Python-ideas mailing list