diff options
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a1f7102df..17b254d82 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -13,6 +13,7 @@ __all__ = ['select', 'piecewise', 'trim_zeros', import warnings import types +import sys import numpy.core.numeric as _nx from numpy.core import linspace from numpy.core.numeric import ones, zeros, arange, concatenate, array, \ @@ -1596,7 +1597,18 @@ import re def _get_nargs(obj): if not callable(obj): raise TypeError, "Object is not callable." - if hasattr(obj,'func_code'): + if sys.version_info[0] >= 3: + import inspect + spec = inspect.getargspec(obj) + nargs = len(spec.args) + if spec.defaults: + ndefaults = len(spec.defaults) + else: + ndefaults = 0 + if inspect.ismethod(obj): + nargs -= 1 + return nargs, ndefaults + elif hasattr(obj,'func_code'): fcode = obj.func_code nargs = fcode.co_argcount if obj.func_defaults is not None: |