<div class="gmail_quote">On Tue, May 31, 2011 at 4:18 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Eric Snow wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Looking at the ABC code [1], I noticed that Mapping's __eq__ method can return NotImplemented.  This got me curious as to why you would return NotImplemented and not raise a TypeError or a NotImplementedError.  <br>
</blockquote>
<br></div>
My understanding is that if your object does not know how to perform the desired action you should return NotImplemented; Python will then give the other object a chance to perform the operation (after all, it may know how), and if the other object also returns NotImplemented then Python itself will raise a TypeError.<br>

<br>
If the first object were to raise TypeError (or any exception), the second object would not get the chance to try.<br><font color="#888888">
<br></font></blockquote><div><br></div><div>RIght.  But the operator code could very well handle the appropriate exception instead of handling a return value of NotImplemented.  Hence my further questions regarding performance and identifiability.  My guess is that it's ultimately because of speed. </div>
<div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888">
~Ethan~<br>
</font></blockquote></div><br>