From b420099bd57644643787553ad25c07b27574980e Mon Sep 17 00:00:00 2001 From: Colin Baumgarten Date: Wed, 4 Jan 2017 21:48:00 +0100 Subject: [PATCH] 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 "", line 1, in File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/__init__.py", line 216, in from .graphicsItems.HistogramLUTItem import * File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/HistogramLUTItem.py", line 10, in from .GradientEditorItem import * File "/usr/local/lib/python3.5/dist-packages/pyqtgraph/graphicsItems/GradientEditorItem.py", line 354, in 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. --- pyqtgraph/graphicsItems/GradientEditorItem.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 6ce06b61..f359ff11 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -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