[Python-ideas] PEP-3151 pattern-matching

Eric Smith eric at trueblade.com
Sun Apr 24 12:15:33 CEST 2011


> Guido van Rossum <guido at python.org> wrote:
>>On Fri, Apr 8, 2011 at 11:18 AM, Antoine Pitrou <solipsis at
pitrou.net> wrote:
>> On Fri, 8 Apr 2011 10:11:34 -0700
>> Guido van Rossum <guido at python.org> wrote:
>>> With apologies for not reading the PEP or this thread in full, some
comments:
>>>
>>> - I really like the syntax "except <exc> [as <var>] [if <test>]:".
>>> This addresses a pretty common use case in my experience. I don't care
>>> for the alternate proposed syntax that started this thread. I'm not
>>> sure that the 'if' subclause makes sense without the 'as' subclause,
>>> since most likely you'd want to refer to the caught exception. I note
>>> that it is more powerful than putting "if not <test>: raise" in the
>>> body of the except-clause, because it will allow subsequent except
>>> clauses to match still. I also note that it is a much "cleaner" change
>>> than (again) reorganizing the exception hierarchy, since there is no
>>> backward compatibility to consider.
>>
>> My main issue with said new syntax is that it doesn't make things much
>> easier to write.

>As I explained in other messages, it also adds semantics that are not
>so easily emulated with the existing syntax (you'd have to repeat code
>or use nested try/except blocks).

Interestingly, this is one of the few (only?) .NET features that is
exposed in Visual Basic but not in C#. Maybe there's something to learn
from that?

http://blogs.msdn.com/b/jaredpar/archive/2008/10/09/vb-catch-when-why-so-special.aspx

Eric.



More information about the Python-ideas mailing list