[Python-Dev] PEP 3151 from the BDFOP

Barry Warsaw barry at python.org
Mon Aug 29 23:21:05 CEST 2011


On Aug 24, 2011, at 12:51 PM, Nick Coghlan wrote:

>On Wed, Aug 24, 2011 at 9:57 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Using IOError.__new__ is the easiest way to ensure that all code
>> raising IO errors takes advantage of the errno mapping. Otherwise you
>> may get APIs raising the proper subclasses, and other APIs always
>> raising base IOError (it doesn't happen often, but some Python
>> library code raises an IOError with an explicit errno).
>
>It's also the natural place to put the errno->exception type mapping
>so that existing code will raise the new errors without requiring
>modification. We could spell it as a new class method ("from_errno" or
>similar), but there isn't any ambiguity in doing it directly in
>__new__, so a class method seems pointlessly inconvenient.

As I mentioned, my main concern with this is the surprise factor for people
debugging and reading the code.  A class method would solve that, but looks
uglier and doesn't work with existing code.

-Barry



More information about the Python-Dev mailing list