title: How to optimize python code in pure pythonic way without cythonizing it
body: <h2>Edited:</h2>
  <p><em>(This post has been largely edited compared to its previous version).</em></p>
  <p>For test purpose I have a module, say, <code>ptest.py</code> :</p>
  <pre class="lang-py prettyprint-override"><code># ptest.py
  def testfunc(*args) :
      # Some process that can take significant time. There may be some integers larger than 2^64.
  </code></pre>
  <p>After cythonizing it to, say, <code>ctest.pyx</code> I got an increase in performance with some further tests (as expected).</p>
  <p>Now for some integer value large enough the program may throw <code>OverflowError</code> while in pure python that might not happen. In this case, can I raise <code>SomeError</code> with information (say, <code>ValueError('The number should not be greater than some value')</code>) in cython as we do in python ?</p>
  <p>Even I did the same,</p>
  <pre class="lang-py prettyprint-override"><code>if n &gt; 2**64:
      raise ValueError(&quot;Number should be a non negative integer less than 2^64.&quot;)
  </code></pre>
  <p>it kept showing: <code>OverflowError: Python int too large to convert to C unsigned long</code>. Seems to ignore the condition completely.</p>
  <p>So, how can I inform the user ? And finally, can I use cython in pure python without cythonizing the entire program (that is without setup, build etc.) as I don't want to lose those functionality of python (in this case raising Exception, handling sufficiently large integer etc.)?</p>
  <p>I tried other methods from <code>cython</code> module (following <code>Cython</code> doc.) like, <code>cython.declare</code>, <code>cython.exceptval</code> etc. in <code>.py</code> file but they all seem to be a failure in improving the performance. I haven't approached <code>ctypes</code> yet as I want the proper technique beforehand.</p>