<div dir="ltr">Actually, they don't have a __hash__ either -- they just inherit the default __hash__ from object, just as they inherit __eq__ from object (and both just use the address of the object). I can see many concerns with trying to define __eq__ for exceptions in general -- often there are a variety of fields, not all of which perhaps should be considered when comparing, and then there are user-defined exceptions which may have other attributes. I don't know what your use case was, but if, as you say, the exceptions you care about already have `args` attributes, maybe you should just compare that (and the type).<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 24, 2015 at 3:43 PM, Ionel Cristian Mărieș <span dir="ltr"><<a href="mailto:contact@ionelmc.ro" target="_blank">contact@ionelmc.ro</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">Hey everyone,<br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">I was writing a test the other day and I wanted to assert that some function raises some exception, but with some exact value. Turns out you cannot compare OSError("foobar") to OSError("foobar") as it doesn't have any __eq__. (it's the same for all exceptions?)<br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">I think exceptions are great candidates to have an __eq__ method - they already have a __hash__ (that's computed from the contained values) and they are already containers in a way (they all have the `args` attribute).<br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif">Comparing exceptions in a test assertion seems like a good usecase for this.<br clear="all"></div><div><div><div dir="ltr"><div><div><span style="font-family:trebuchet ms,sans-serif"><span style="color:rgb(51,51,51)"><br><font><span style="color:rgb(51,51,51)">Thanks,</span><br><span style="color:rgb(153,153,153)">-- Ionel</span></font></span><font><font style="color:rgb(153,153,153)"> Cristian Mărieș, <a href="http://blog.ionelmc.ro" target="_blank">blog.ionelmc.ro</a><br></font></font></span></div></div></div></div></div>
</div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div>
</div>