2010/7/2 Guido van Rossum <span dir="ltr">&lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Fri, Jul 2, 2010 at 10:28 AM, Nick Coghlan &lt;<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>&gt; wrote:<br>

&gt; On Sat, Jul 3, 2010 at 3:13 AM, Craig Citro &lt;<a href="mailto:craigcitro@gmail.com">craigcitro@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &quot;1/0&quot; is much faster to type than &quot;raise SomeError&quot; and serves the same<br>
&gt;&gt;&gt; purpose sometimes for debugging purposes.  Let&#39;s not forget that not<br>
&gt;&gt;&gt; all code is written for eternity :)<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Doesn&#39;t &quot;raise&quot; do the same thing for just two extra characters?<br>
&gt;<br>
&gt; No, raise on its own is only valid in an exception handler. Writing<br>
&gt; &quot;1/0&quot; is at least somewhat common as an idiom for forcing a<br>
&gt; ZeroDivisionError in examples and in test harnesses (I know I have<br>
&gt; used it for both of those things many times).<br>
&gt;<br>
&gt; Given the diverse range of uses Python is put to, moving things from<br>
&gt; runtime to compile time can definitely have significant unexpected<br>
&gt; consequences (hence why many of us would be hesitant to consider an<br>
&gt; implementation that made such changes to be an actual Python<br>
&gt; implementation).<br>
<br>
+1 on not changing this.<br>
<br>
For one, this will most likely break a large amount of 3rd party and<br>
stdlib software -- there are tons of statements like this that are<br>
practically unreachable or intentional.<br>
<br>
Second, I don&#39;t think it&#39;s going to make the kind of difference the OP<br>
is thinking of. Since Python is totally dynamic, and doesn&#39;t have<br>
macros, the only cases that would be caught would be things you are<br>
unlikely to type by accident -- like 1/0 or 1+&quot;1&quot;. In other languages<br>
that have this behavior, there is usually a benefit where the<br>
arguments involved are *variables* whose type is known to the<br>
compiler, so it will catch things like (simple C example)<br>
<br>
#define FOO 0<br>
main() {<br>
  printf(&quot;%d\n&quot;, 1/FOO);<br>
}<br>
<br>
However the equivalent Python<br>
<br>
FOO = 0<br>
def main():<br>
  print 1/FOO<br>
<br>
cannot be rejected at compile time because there is insufficient<br>
evidence that the value of FOO won&#39;t be changed before main() is<br>
called.<br>
<br>
I even reject the substitution of &quot;raise ZeroDivisionError&quot; for &quot;1/0&quot;<br>
since (a) nobody cares about such an optimization, and (b) it would<br>
break introspection and invalidate tests. (We have a long history of<br>
constant propagation in expressions causing subtle bugs. This could be<br>
worse.)<br>
<font color="#888888"><br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>
</font></blockquote><div><br></div><div>from __future__ import compile_checks</div><div><br></div><div>Cesare Di Mauro</div>