Repository: scikit-image/scikit-image

Issue:
TypeError when running in Python optimized mode
## Description
I'm investigating running a project, which use scikit-image, with python optimized mode.
The problem happens because the `_parse_docs()` function try to regex parse a docstring which is None.
I already fixed it on my side and can provide the patch ..

## Way to reproduce
scikit_image ==  0.14.0

`python2.7 -OO -c "import skimage.measure"`



Discussion:
I think you meant to do

```
import skimage.measure
```

I don't know why `scikit_image.measure` doesn't raise a module not found error.

I was able to reproduce this on my machine (linux + conda + python2.7 + pip install, conda install might also cause I problem).
I guess you meant 
```
python2.7 -O -c "import skimage.measure"
```
? 
I cannot reproduce your problem, this line executes fine on my machine...
sorry emmanuelle, I guess i'm not thinking staight.

@gst, the error:
```
ImportError: No module named scikit_image.measure
```
is factual. There is no module called `scikit_image` just `skimage` happy coding!

oupsss my bad, effectively it's `skimage.measure`
I cannot reproduce as well.
@gst could you elaborate on your setup?
No particular setup, just use `python -OO` 
**NB:** I'm not using master but **v0.14.x**  given master doesn't support anymore python2..



It would be great if you could check whether this bug persists on Python 3 with the latest master.  If so, you are welcome to submit a patch, as long as it does not adversely impact the current behavior.  Thanks!
Still nothing 😕 :
```
[~]$ python2.7 --version
Python 2.7.15
[~]$ python2.7 -O -c "import skimage.measure; print skimage"
<module 'skimage' from '/usr/local/lib/python2.7/site-packages/skimage/__init__.pyo'>
[~]$ python2.7 -O -c "import skimage.measure; print skimage.__version__"
0.14.0
```
@gst, few questions:


1. where did you install scikit-image from? git? pypi, conda?
2. Can you try your install in a fresh environment?
3. Finally it seems that you are running the code from within either the `site-packages` directory, or the git directory. Generally, this is a bad idea as python has trouble finding the right version of the library.

I have a feeling the issue is related to 3 and either an older version of 0.14 or a version of 0.14 that is too new.
and now like most of you I can't reproduce anymore as if optimize mode wasn't enabled anymore while I still use the **-OO** option.. hhoooo well ; I've reinstalled in a venv meanwhile, I think I'm going to re-do all from scratch..
if I can't reproduce anymore reliably I'll close..
if you are trying to compile it yourself, we've been having issues with the bulid.

I have a feeling it is related to cython (well because python typically updates well). Try `make clean` before you do install it from the git directory.
@gst, I guess it took me some time to understand the bug. Seems like it is the same thing as:

https://stackoverflow.com/questions/52242859/file-e-python-lib-re-py-line-229-in-finditer-return-compilepattern-flags

Please submit your fix for this bug. I would be interested in reviewing it.


Hmm, still not able to reproduce though :/ I should just not work past 10pm .....
@hmaarrfk this is exactly *that* error :)
**NB:**  my bad, this is with `python -OO` actually, this is what disable docstrings. -O only disables \_\_debug\_\_
I'll submit my PR probably during the day.
( what I don't get is that in a pip --user install with pypi wheel on a computer A I reproduce the error but not on a second computer B.. I'm looking to figure out what's going on ) 

Resolving patch:
diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py
--- a/skimage/measure/_regionprops.py
+++ b/skimage/measure/_regionprops.py
@@ -631,7 +631,7 @@ def _parse_docs():
     import re
     import textwrap
 
-    doc = regionprops.__doc__
+    doc = regionprops.__doc__ or ''
     matches = re.finditer('\*\*(\w+)\*\* \:.*?\n(.*?)(?=\n    [\*\S]+)',
                           doc, flags=re.DOTALL)
     prop_doc = dict((m.group(1), textwrap.dedent(m.group(2))) for m in matches)
@@ -648,4 +648,6 @@ def _install_properties_docs():
         setattr(_RegionProperties, p, property(getattr(_RegionProperties, p)))
 
 
-_install_properties_docs()
+if __debug__:
+    # don't install docstrings when in optimized/non-debug mode
+    _install_properties_docs()


Test patch:
diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py
--- a/skimage/measure/tests/test_regionprops.py
+++ b/skimage/measure/tests/test_regionprops.py
@@ -476,6 +476,11 @@ def test_cache():
 
 
 def test_docstrings_and_props():
+    def foo():
+        """foo"""
+
+    has_docstrings = bool(foo.__doc__)
+
     region = regionprops(SAMPLE)[0]
 
     docs = _parse_docs()
@@ -483,11 +488,13 @@ def test_docstrings_and_props():
 
     nr_docs_parsed = len(docs)
     nr_props = len(props)
-    assert_equal(nr_docs_parsed, nr_props)
-
-    ds = docs['weighted_moments_normalized']
-    assert 'iteration' not in ds
-    assert len(ds.split('\n')) > 3
+    if has_docstrings:
+        assert_equal(nr_docs_parsed, nr_props)
+        ds = docs['weighted_moments_normalized']
+        assert 'iteration' not in ds
+        assert len(ds.split('\n')) > 3
+    else:
+        assert_equal(nr_docs_parsed, 0)
 
 
 def test_incorrect_coordinate_convention():