[Python-ideas] Comparable exceptions

Guido van Rossum guido at python.org
Wed Feb 25 17:18:26 CET 2015


I am firmly -1 on any changes here. It would have been a nice idea when we
first introduced exceptions. Fixing this now isn't going to make much of a
difference, and the internal structure of exceptions is murky enough that
comparing 'args' alone doesn't cut it.

On Wed, Feb 25, 2015 at 5:32 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> On Wed, Feb 25, 2015 at 03:03:40PM +0200, Ionel Cristian Mărieș wrote:
> > Yes, it does, however my assertion looks similar to this:
> >
> >     assert result == [1,2, (3, 4, {"bubu": OSError('foobar')})]
>
> I'm not keen on using assert like that. I think that using assert for
> testing is close to abuse of the statement, and it makes it impossible
> to test your code running with -O.
>
> But regardless of whether that specific test is good practice or not, I
> think it is reasonable for exception instances to have a more useful
> __eq__ than that provided by inheriting from object. Perhaps add
> something like this to BaseException:
>
>     def __eq__(self, other):
>         if isinstance(other, type(self)):
>             return self.args == other.args
>         return NotImplemented
>
>
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150225/4720f864/attachment.html>


More information about the Python-ideas mailing list