Fix crash when running pyqtgraph with python -OO

Running pyqtgraph with python -OO gives the following crash

colin@desktop:~$ python3 -OO -c 'import pyqtgraph'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/__init__.py", line 216, in <module>
    from .graphicsItems.HistogramLUTItem import *
  File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/HistogramLUTItem.py", line 10, in <module>
    from .GradientEditorItem import *
  File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/GradientEditorItem.py", line 354, in <module>
    class GradientEditorItem(TickSliderItem):
  File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/GradientEditorItem.py", line 480, in GradientEditorItem
    @addGradientListToDocstring()
  File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/GradientEditorItem.py", line 30, in dec
    fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

The cause is the @addGradientListToDocstring() annotation in
GradientEditorItem.py that cannot handle functions without docstrings as
produced when using the python -OO option.

Fix this by only adding the gradient list to the docstring if the docstring is
not None.
This commit is contained in:
Colin Baumgarten 2017-01-04 21:48:00 +01:00
parent fe90f46bdd
commit b420099bd5

View File

@ -27,7 +27,8 @@ Gradients = OrderedDict([
def addGradientListToDocstring():
"""Decorator to add list of current pre-defined gradients to the end of a function docstring."""
def dec(fn):
fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']')
if fn.__doc__ is not None:
fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']')
return fn
return dec