I think you will have to put the ``if scale_pcov`` at line 536, inside the condition for valid pcov.

I think the case covers when the outerproduct of Jacobian (Hessian) is not invertible, for example reduced rank/perfect multicollinearity.
I think with have ``pcov is None`` in that case.
I never looked at the case when ``(len(ydata) > len(p0))`` doesn't hold. I don't know what leastsq returns in that case. (doesn't make much statistical sense.)

returning ``inf`` is reasonable, but Travis could also have chosen nan or None instead.