title: Integer overflow in Python3
body: <p>I'm new to Python, I was reading <a href="https://docs.python.org/3/library/doctest.html#module-doctest" rel="noreferrer">this</a> page where I saw a weird statement:</p>
  
  <pre><code>if n+1 == n:  # catch a value like 1e300
      raise OverflowError("n too large")
  </code></pre>
  
  <p>x equals to a number greater than it?! I sense a disturbance in the Force.</p>
  
  <p>I know that in Python 3, integers don't have fixed byte length. Thus, there's no integer overflow, like how C's <code>int</code> works. But of course the memory can't store infinite data.</p>
  
  <p>I think that's why the result of <code>n+1</code> can be the same as <code>n</code>: Python can't allocate more memory to preform the summation, so it is skipped, and <code>n == n</code> is true. Is that correct?</p>
  
  <p>If so, this could lead to incorrect result of the program. Why don't Python raise an error when operations are not possible, just like C++'s <code>std::bad_alloc</code>?</p>
  
  <p>Even if <code>n</code> is not too large and the check evaluates to false, <code>result</code> - due to the multiplication - would need much more bytes. Could <code>result *= factor</code> fail for the same reason?</p>
  
  <p>I found it in the offical Python documentation. Is it really the correct way to check big integers / possible integer "overflow"?</p>