Repository: lmfit/lmfit-py

Issue:
inspect.getargspec() fails with Python 3.6, should use inspect.getfullargspec(), I think.
`inspect.getargspec()` has been deprecated in Python 3 (though I feel obliged to say that I do not see any warnings when using `inspect.getargspec()` with Python 3.5.2),  and has been *removed* in 3.6.  

The recommendation appears to be to use `inspect.getfullargspec()`, with a slightly different return value (improved for sure in Python3, but an incompatible change),  or`inspect.signature()`, which has a very different interface.  Neither are compatible with Python 2.7, and `six` does not appear to have a convenience function to handle the change.   My inclination would be to use `getfullargspec()`.

But I must also say that my inclination is to de-emphasize the importance of supporting Python 3.6.    I'm all in favor of using Python 3, but much of my own code base and distribution depends on wxPython and Anaconda.  Until wxPython is readily available for Anaconda's Python 3, I'm stuck using Python 2.7 in much of my production work, and my incentive and enthusiasm are really small for keeping up with breakages due to Python itself or the standard library.   I had hoped we could be moving to Python3-only in the near future, but that's not easy when they keep breaking the standard library.

To be specific, holding the next release of lmfit for a fix to *this* issue is not a priority for me.  OTOH, if it is a priority for someone else, a PR would be most welcome. 




Discussion:
I'd recommend against using `inspect.getfullargspec()` as this function was actually deprecated since version 3.5. So if we're going to fix it for real then one should probably spend some time in getting it to work with `inspect.signature()`. But I do agree that this shouln't be a blocker.
I think the 3.6 docs say getfullargspec() is not deprecated. But I could be wrong on that....
I see, you are right - it indeed says that the decision to deprecate that function was reversed. I was probably reading the 3.5.2 docs...
Phew.  That Seems much easier to me.
I just looked a bit at Python 3.6 and it turns out that `inspect.getargspec` is still present. In [this thread](https://bugs.python.org/issue25486#msg258007) it actually states that it's still in version 3.6 - despite what the docs say... Since all `lmfit` tests pass also for version 3.6, I'd suggest to leave this issue open for now and deal with it once the Python developers have decided what they're going to do for real ;)
@reneeotten Wow, that is wild.  I mean, the whole deprecation of `inspect.getargspec` is pretty irritating and seems like deliberate breaking of backward compatibility just for the sake of proving that it can be done.   I'd like to believe that the Python devs were convinced to undo that decision, but I don't have a lot of trust in that.    That is, I suppose we're still better off migrating to `inspect.getfullargspec()` eventually.




Resolving patch:
diff --git a/lmfit/model.py b/lmfit/model.py
--- a/lmfit/model.py
+++ b/lmfit/model.py
@@ -203,9 +203,14 @@ def _parse_params(self):
                 kw_args[name] = defval
             keywords_ = list(kw_args.keys())
         else:
-            argspec = inspect.getargspec(self.func)
-            pos_args = argspec.args[:]
-            keywords_ = argspec.keywords
+            try:  # PY3
+                argspec = inspect.getfullargspec(self.func)
+                keywords_ = argspec.varkw
+            except AttributeError:  # PY2
+                argspec = inspect.getargspec(self.func)
+                keywords_ = argspec.keywords
+
+            pos_args = argspec.args
             kw_args = {}
             if argspec.defaults is not None:
                 for val in reversed(argspec.defaults):


Test patch: