[Python-ideas] PEP-3151 pattern-matching

Devin Jeanpierre jeanpierreda at gmail.com
Wed May 18 14:24:04 CEST 2011


On Wed, May 18, 2011 at 6:07 AM, dag.odenhall at gmail.com
<dag.odenhall at gmail.com> wrote:
> Interesting. If that is intentional I'd advocate against it unless
> there's a strong argument for it.
>
> Another idea (also likely already proposed) would be to match against
> instances as well, by the 'args' attribute:
>
> try:
>    ...
> except IOError(32):  # isinstance IOError and .args == (32,)
>    ...
>
> If this seems crazy consider that it's (to some extent) similar to the
> behavior of 'raise'.

Unfortunately, as described it wouldn't match IOError(32, 'Blah blah
blah'). Although maybe it makes sense to create an Anything builtin,
which is equal to everything, such that IOError(X, Y) == IOError(X,
Anything) == IOError(X, Z) for all X, Y, and Z (except stupid X like X
= nan).

I do like it.

Devin Jeanpierre



More information about the Python-ideas mailing list