Wouldn’t a simpler Python implementation just duplicate the high-level exception matching logic?
def exception_matches(exc, expected):
"""Return whether or not "raise exc" will be caught by "except expected"."""
if isinstance(exc, type):
return isubclass(exc, expected)
return isinstance(exc, excepted)
Have I missed any cases, or some other issue?
It would be nice to have an official way to do this. The operator module makes sense to me.