Repository: numpy/numpy

Issue:
Numpy crashes with -OO
Hello, I ran `$ python -OO -c 'import numpy'` on a fresh miniconda install (after `$ conda install numpy`) and I got the following output:

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/obernardo/miniconda/lib/python2.7/site-packages/numpy/__init__.py", line 191, in <module>
    from . import ma
  File "/Users/obernardo/miniconda/lib/python2.7/site-packages/numpy/ma/__init__.py", line 49, in <module>
    from . import extras
  File "/Users/obernardo/miniconda/lib/python2.7/site-packages/numpy/ma/extras.py", line 438, in <module>
    :np.apply_over_axes.__doc__.find('Notes')].rstrip() + \
AttributeError: 'NoneType' object has no attribute 'find'
```

Running `$ python` gives me the following output (I am running OS X Mavericks on a Dec-2010 MacBook Pro):

```
Python 2.7.8 |Continuum Analytics, Inc.| (default, Aug 21 2014, 15:21:46) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
```

Finally, running `python -c 'import numpy'` works normally. I hope this is enough information for you all, but please let me know if you need more. (It's the second bug report I submit in my life, and the first one was about a typo in documentation!)

Thanks a lot for making numpy available to us, it is a very, very useful tool that works greatly for me.



Discussion:

Resolving patch:
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -434,8 +434,10 @@ def apply_over_axes(func, a, axes):
                 raise ValueError("function is not returning "
                         "an array of the correct shape")
     return val
-apply_over_axes.__doc__ = np.apply_over_axes.__doc__[
-    :np.apply_over_axes.__doc__.find('Notes')].rstrip() + \
+
+if apply_over_axes.__doc__ is not None:
+    apply_over_axes.__doc__ = np.apply_over_axes.__doc__[
+        :np.apply_over_axes.__doc__.find('Notes')].rstrip() + \
     """
 
     Examples
@@ -462,7 +464,7 @@ def apply_over_axes(func, a, axes):
     [[[46]
       [--]
       [124]]]
-"""
+    """
 
 
 def average(a, axis=None, weights=None, returned=False):


Test patch:
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1,12 +1,14 @@
 from __future__ import division, absolute_import, print_function
 
 import warnings
+import sys
 
 import numpy as np
 from numpy.testing import (
     run_module_suite, TestCase, assert_, assert_equal, assert_array_equal,
     assert_almost_equal, assert_array_almost_equal, assert_raises,
-    assert_allclose, assert_array_max_ulp, assert_warns, assert_raises_regex
+    assert_allclose, assert_array_max_ulp, assert_warns,
+    assert_raises_regex, dec
     )
 from numpy.random import rand
 from numpy.lib import *
@@ -2094,6 +2096,8 @@ def test_string_arg(self):
 
 
 class TestAdd_newdoc(TestCase):
+
+    @dec.skipif(sys.flags.optimize == 2)
     def test_add_doc(self):
         # test np.add_newdoc
         tgt = "Current flat index into the array."
diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py
--- a/numpy/lib/tests/test_utils.py
+++ b/numpy/lib/tests/test_utils.py
@@ -3,7 +3,7 @@
 import sys
 from numpy.core import arange
 from numpy.testing import (
-    run_module_suite, assert_, assert_equal
+    run_module_suite, assert_, assert_equal, dec
     )
 from numpy.lib import deprecate
 import numpy.lib.utils as utils
@@ -14,6 +14,7 @@
     from StringIO import StringIO
 
 
+@dec.skipif(sys.flags.optimize == 2)
 def test_lookfor():
     out = StringIO()
     utils.lookfor('eigenvalue', module='numpy', output=out,