[SciPy-Dev] usage of inspect.getargspec ?
Thu Jan 5 21:09:13 CST 2012
triggered by the recent commit, I started to look a bit more at
Until now I have seen it mainly in convenience code were it makes it
easier for users but that I usually don't use, in this case it is part
of essential code.
The main problem with inspect.getargspec is that it gets easily
confused by `self` if it is an instance method and by keywords and
recent fix for curve_fit https://github.com/scipy/scipy/pull/92
my only other experience is with numpy.vectorize that has some tricky
features and IIRC has some cases of flexible arguments that don't
I don't think the changes to fmin_ncg break anything in statsmodels
since we have identical simple signatures for the main functions,
hessians and gradients, but I think it would break if we add a keyword
argument to the Hessians.
It also would be possible to work around any limitations by writing a
wrapper or a lambda function.
What experience do others have with inspect?
My experience is mostly unpleasant but I never looked much at the
details of inspect, just avoided it as much as possible.
Is it ok to use it in basic library code like the optimizers?
Just asking for general comments and since the pull request is closed.
-------------- next part --------------
# -*- coding: utf-8 -*-
Created on Thu Jan 05 20:19:28 2012
Author: Josef Perktold
import numpy as np
def func1(self, x, p=None):
def func2(x, p, z=None):
def func1(x, p=None):
def func1a(x, p, z=None):
def func2(x, **kwds):
def func3(x, *args):
print 'func0', inspect.getargspec(func0)
print 'func1', inspect.getargspec(func1)
print 'func1a', inspect.getargspec(func1a)
print 'func2', inspect.getargspec(func2)
print 'func3', inspect.getargspec(func3)
my = My()
print 'class func1', inspect.getargspec(my.func1)
print 'class func2', inspect.getargspec(my.func2)
More information about the SciPy-Dev