Repository: lmfit/lmfit-py

Issue:
Check for None in __doc__ before changing it.
Python code byte-compiled with -OO has doc-strings stripped out. 

This creates problems when compiling different packages which changes the doc-strings by doing something like this:
     **doc** += "additional text"
(when the docstring is 'None', this will fail).

lmfit/models.py does this and thus creates problems when trying to bytecompile it with the -OO option using  cx_freeze/py2exe.

In order to fix this, I would propose to change all the lines in lmfit/models.py which say:
     **doc** = XXXX.**doc** + COMMON_DOC
with
    **doc** = XXXX.**doc** + COMMON_DOC if **doc** else COMMON_DOC

See also:
http://bugs.python.org/issue23189#
http://stackoverflow.com/questions/22299532/unsupported-operand-types-for-nonetype-and-str-winappdbg-error-after-c



Discussion:
That sounds fine. Thanks for pointing this out. Would you be able to write a PR?


Resolving patch:
diff --git a/lmfit/models.py b/lmfit/models.py
--- a/lmfit/models.py
+++ b/lmfit/models.py
@@ -97,7 +97,7 @@ def guess(self, data, **kwargs):
 
 
 class LinearModel(Model):
-    __doc__ = linear.__doc__ + COMMON_DOC
+    __doc__ = linear.__doc__ + COMMON_DOC if linear.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(LinearModel, self).__init__(linear, *args, **kwargs)
 
@@ -110,7 +110,7 @@ def guess(self, data, x=None, **kwargs):
 
 
 class QuadraticModel(Model):
-    __doc__ = parabolic.__doc__ + COMMON_DOC
+    __doc__ = parabolic.__doc__ + COMMON_DOC if parabolic.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(QuadraticModel, self).__init__(parabolic, *args, **kwargs)
 
@@ -150,7 +150,7 @@ def guess(self, data, x=None, **kwargs):
 
 
 class GaussianModel(Model):
-    __doc__ = gaussian.__doc__ + COMMON_DOC
+    __doc__ = gaussian.__doc__ + COMMON_DOC if gaussian.__doc__ else ""
     fwhm_factor = 2.354820
     def __init__(self, *args, **kwargs):
         super(GaussianModel, self).__init__(gaussian, *args, **kwargs)
@@ -163,7 +163,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class LorentzianModel(Model):
-    __doc__ = lorentzian.__doc__ + COMMON_DOC
+    __doc__ = lorentzian.__doc__ + COMMON_DOC if lorentzian.__doc__ else ""
     fwhm_factor = 2.0
     def __init__(self, *args, **kwargs):
         super(LorentzianModel, self).__init__(lorentzian, *args, **kwargs)
@@ -176,7 +176,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class VoigtModel(Model):
-    __doc__ = voigt.__doc__ + COMMON_DOC
+    __doc__ = voigt.__doc__ + COMMON_DOC if voigt.__doc__ else ""
     fwhm_factor = 3.60131
     def __init__(self, *args, **kwargs):
         super(VoigtModel, self).__init__(voigt, *args, **kwargs)
@@ -191,7 +191,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class PseudoVoigtModel(Model):
-    __doc__ = pvoigt.__doc__ + COMMON_DOC
+    __doc__ = pvoigt.__doc__ + COMMON_DOC if pvoigt.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(PseudoVoigtModel, self).__init__(pvoigt, *args, **kwargs)
         self.set_param_hint('fraction', value=0.5)
@@ -203,7 +203,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class Pearson7Model(Model):
-    __doc__ = pearson7.__doc__ + COMMON_DOC
+    __doc__ = pearson7.__doc__ + COMMON_DOC if pearson7.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(Pearson7Model, self).__init__(pearson7, *args, **kwargs)
         self.set_param_hint('expon',  value=1.5)
@@ -215,7 +215,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class StudentsTModel(Model):
-    __doc__ = students_t.__doc__ + COMMON_DOC
+    __doc__ = students_t.__doc__ + COMMON_DOC if students_t.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(StudentsTModel, self).__init__(students_t, *args, **kwargs)
 
@@ -225,7 +225,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class BreitWignerModel(Model):
-    __doc__ = breit_wigner.__doc__ + COMMON_DOC
+    __doc__ = breit_wigner.__doc__ + COMMON_DOC if breit_wigner.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(BreitWignerModel, self).__init__(breit_wigner, *args, **kwargs)
 
@@ -236,7 +236,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class LognormalModel(Model):
-    __doc__ = lognormal.__doc__ + COMMON_DOC
+    __doc__ = lognormal.__doc__ + COMMON_DOC if lognormal.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(LognormalModel, self).__init__(lognormal, *args, **kwargs)
 
@@ -247,7 +247,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class DampedOscillatorModel(Model):
-    __doc__ = damped_oscillator.__doc__ + COMMON_DOC
+    __doc__ = damped_oscillator.__doc__ + COMMON_DOC if damped_oscillator.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(DampedOscillatorModel, self).__init__(damped_oscillator, *args, **kwargs)
 
@@ -257,7 +257,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
         return update_param_vals(pars, self.prefix, **kwargs)
 
 class ExponentialGaussianModel(Model):
-    __doc__ = expgaussian.__doc__ + COMMON_DOC
+    __doc__ = expgaussian.__doc__ + COMMON_DOC if expgaussian.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(ExponentialGaussianModel, self).__init__(expgaussian, *args, **kwargs)
 
@@ -266,7 +266,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
         return update_param_vals(pars, self.prefix, **kwargs)
 
 class SkewedGaussianModel(Model):
-    __doc__ = skewed_gaussian.__doc__ + COMMON_DOC
+    __doc__ = skewed_gaussian.__doc__ + COMMON_DOC if skewed_gaussian.__doc__ else ""
     fwhm_factor = 2.354820
     def __init__(self, *args, **kwargs):
         super(SkewedGaussianModel, self).__init__(skewed_gaussian, *args, **kwargs)
@@ -277,7 +277,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
         return update_param_vals(pars, self.prefix, **kwargs)
 
 class DonaichModel(Model):
-    __doc__ = donaich.__doc__ + COMMON_DOC
+    __doc__ = donaich.__doc__ + COMMON_DOC if donaich.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(DonaichModel, self).__init__(donaich, *args, **kwargs)
 
@@ -287,7 +287,7 @@ def guess(self, data, x=None, negative=False, **kwargs):
 
 
 class PowerLawModel(Model):
-    __doc__ = powerlaw.__doc__ + COMMON_DOC
+    __doc__ = powerlaw.__doc__ + COMMON_DOC if powerlaw.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(PowerLawModel, self).__init__(powerlaw, *args, **kwargs)
 
@@ -302,7 +302,7 @@ def guess(self, data, x=None, **kwargs):
 
 
 class ExponentialModel(Model):
-    __doc__ = exponential.__doc__ + COMMON_DOC
+    __doc__ = exponential.__doc__ + COMMON_DOC if exponential.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(ExponentialModel, self).__init__(exponential, *args, **kwargs)
 
@@ -316,7 +316,7 @@ def guess(self, data, x=None, **kwargs):
 
 
 class StepModel(Model):
-    __doc__ = step.__doc__ + COMMON_DOC
+    __doc__ = step.__doc__ + COMMON_DOC if step.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(StepModel, self).__init__(step, *args, **kwargs)
 
@@ -332,7 +332,7 @@ def guess(self, data, x=None, **kwargs):
 
 
 class RectangleModel(Model):
-    __doc__ = rectangle.__doc__ + COMMON_DOC
+    __doc__ = rectangle.__doc__ + COMMON_DOC if rectangle.__doc__ else ""
     def __init__(self, *args, **kwargs):
         super(RectangleModel, self).__init__(rectangle, *args, **kwargs)
         self.set_param_hint('midpoint',


Test patch: