<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 17, 2010, at 1:59 PM, Steven D'Aprano wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote:<br><blockquote type="cite">The spectrum of options from worst to best is<br></blockquote><blockquote type="cite">1) compare but give the wrong answer<br></blockquote><blockquote type="cite">2) compare but give the right answer<br></blockquote><blockquote type="cite">3) refuse to compare.<br></blockquote><br>Why is 3 the best? If there is a right answer to give, surely giving the <br>right answer it is better than not?<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>From the early days of the decimal module,</div><div>we've thought that mixed float-decimal operations</div><div>are 1) a bit perilous and 2) have few, if any good</div><div>use cases. &nbsp; &nbsp;&nbsp;</div><div><br></div><div>Accordingly, any mixed operations&nbsp;should be explicit&nbsp;</div><div>rather than implicit:</div><div><br></div><div>&nbsp;&nbsp; &nbsp; Decimal('1.1') + Decimal.from_float(2.2)</div><div><br></div><div>is better than:</div><div><br></div><div>&nbsp;&nbsp; &nbsp; Decimal('1.1') + 2.2</div><div><br></div><div>To help the user avoid confusion, we flag the latter with a TypeError:</div><div>unsupported operand type(s) for +: 'Decimal' and 'float'.</div><div><br></div><div>Unfortunately, in&nbsp;Py2.x, implicit mixed comparisons do not</div><div>raise an exception, and instead will silently fail&nbsp;by giving&nbsp;</div><div>an incorrect answer:&nbsp;</div><div><br></div><div><div>&nbsp;&nbsp; &nbsp;&gt;&gt;&gt; Decimal('1.1') &lt; 2.2</div><div>&nbsp;&nbsp; &nbsp;False</div></div><div><br></div><div>IMO, raising the exception is the right thing to do.</div><div>Short of that though, if we're going to give a result,</div><div>it should at least be a correct one.</div><div><br></div><div><br></div><div>Raymond</div><div><br></div><div><br></div><div>New zen:</div><div><br></div><div>* right answers are better wrong</div><div>* but ill-formed questions are best not answered at all</div><div><br></div><div><br></div></body></html>