|
31 | 31 | from ..metrics.pairwise import pairwise_kernels |
32 | 32 | from ..externals import six |
33 | 33 | from ..base import clone |
34 | | - |
| 34 | +from sklearn.externals.funcsigs import signature |
35 | 35 |
|
36 | 36 | class Hyperparameter(namedtuple('Hyperparameter', |
37 | 37 | ('name', 'value_type', 'bounds', |
@@ -116,15 +116,21 @@ def get_params(self, deep=True): |
116 | 116 | # to represent |
117 | 117 | cls = self.__class__ |
118 | 118 | init = getattr(cls.__init__, 'deprecated_original', cls.__init__) |
119 | | - args, varargs, kw, default = inspect.getargspec(init) |
120 | | - if varargs is not None: |
| 119 | + init_sign = signature(init) |
| 120 | + args, varargs = [], [] |
| 121 | + for parameter in init_sign.parameters.values(): |
| 122 | + if (parameter.kind != parameter.VAR_KEYWORD and |
| 123 | + parameter.name != 'self'): |
| 124 | + args.append(parameter.name) |
| 125 | + if parameter.kind == parameter.VAR_POSITIONAL: |
| 126 | + varargs.append(parameter.name) |
| 127 | + |
| 128 | + if len(varargs) != 0: |
121 | 129 | raise RuntimeError("scikit-learn kernels should always " |
122 | 130 | "specify their parameters in the signature" |
123 | 131 | " of their __init__ (no varargs)." |
124 | 132 | " %s doesn't follow this convention." |
125 | 133 | % (cls, )) |
126 | | - # Remove 'self' and store remaining arguments in params |
127 | | - args = args[1:] |
128 | 134 | for arg in args: |
129 | 135 | params[arg] = getattr(self, arg, None) |
130 | 136 | return params |
|
0 commit comments