<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 12, 2011, at 11:30 AM, Eric Snow wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Thu, May 12, 2011 at 6:23 AM, Roy Smith <span dir="ltr"><<a href="mailto:roy@panix.com">roy@panix.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">The docs say:<br>
<br>
[<a href="http://docs.python.org/library/stdtypes.html" target="_blank">http://docs.python.org/library/stdtypes.html</a>]<br>
Objects of different types, except different numeric types and different<br>
string types, never compare equal<br>
<br>
[<a href="http://docs.python.org/release/2.7/reference/expressions.html#notin" target="_blank">http://docs.python.org/release/2.7/reference/expressions.html#notin</a>]<br>
objects of different types (emphasis)always compare unequal<br>
<br></blockquote><div><br></div><div>That definitely makes it unclear.</div></div></blockquote><div><br></div><div>I don't think it's unclear at all.  It's very clear.  Clearly wrong :-)</div><div><br></div><blockquote type="cite"><div class="gmail_quote"><div>A little further down it says that you can customize comparison with the __cmp__ special method. </div></div></blockquote><div><br></div><div>Yes, and that says:</div><div><br></div><div>The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily. You can control comparison behavior of objects of non-built-in types by defining a __cmp__ method or rich comparison methods like __gt__, described in section Special method names.</div><div><br></div><div>I read that as saying that if you implement __eq__(), you must make sure that it returns False if self and other have different types (and likewise, __ne__() should return True for that case).  The same way that it says that obj1.__lt__(obj2) must return a consistent result for all types of obj1 and obj2.<br><br></div><blockquote type="cite"><div class="gmail_quote"><div>Looking over the documentation, it seems like it could be touched up to alleviate any confusion.  Perhaps rewording to make it clear that the described behavior is the default for objects, rather than always the case.</div></div></blockquote><div><br></div><div>That would be a start, but doesn't address this specific problem.  If the docs are changed to say that "type(obj1) != type(obj2) implies obj1 != obj2" in only the default, people will assume that list follows this default rule since it's a built-in type.  Built-in types which don't follow the default rule need to have their behavior documented.</div><div><br></div></div><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>---</div><div>Roy Smith</div><div><a href="mailto:roy@panix.com">roy@panix.com</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></span><br class="Apple-interchange-newline">
</div>
<br></body></html>