[Python-ideas] PEP-3151 pattern-matching
Georg Brandl
g.brandl at gmx.net
Thu May 12 22:15:07 CEST 2011
On 12.05.2011 21:06, M.-A. Lemburg wrote:
> Antoine Pitrou wrote:
>> On Fri, 08 Apr 2011 10:59:16 +0200
>> "M.-A. Lemburg" <mal at egenix.com> wrote:
>>>>
>>>> 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.
>>
>> Another quirk occurred to me today: select.error doesn't derive from
>> EnvironmentError, and so it doesn't have the errno attribute (even
>> though the select module "correctly" instantiates it with a (errno,
>> message) tuple). Also, its str() is borked:
>>
>>>>> e = select.error(4, "interrupted")
>>>>> str(e)
>> "(4, 'interrupted')"
>>>>> raise e
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> select.error: (4, 'interrupted')
>
> Works fine in Python 2.7:
>
>>>> import select
>>>> e = select.error(4, "intr")
>>>> e
> error(4, 'intr')
Note that this is the repr(), while Antoine showed the str().
But the str() looks correct to me as well (for an exception that doesn't
derive from EnvironmentError).
Georg
More information about the Python-ideas
mailing list