[Python-ideas] PEP-3151 pattern-matching
dag.odenhall at gmail.com
dag.odenhall at gmail.com
Wed May 18 12:07:28 CEST 2011
On 18 May 2011 00:41, Chris Rebert <pyideas at rebertia.com> wrote:
> On Tue, May 17, 2011 at 7:14 AM, dag.odenhall at gmail.com
> <dag.odenhall at gmail.com> wrote:
>> Excuse me if this has already been discussed, but couldn't
>> __instancecheck__ be used to add exception types that match with more
>> precision?
>
> Somewhat related bug:
> http://bugs.python.org/issue12029
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'.
More information about the Python-ideas
mailing list