def test_iter_params_does_not_list_obsolete_params(): class Test(object): p1 = params.IntParam('p1') p2 = params.IntParam('p2') obsolete = params.ObsoleteParam('obsolete', 'not included in params') assert set(params.iter_params(Test())) == {'p1', 'p2'}
def test_iter_params_does_not_list_obsolete_params(): class Test: p1 = params.IntParam("p1") p2 = params.IntParam("p2") obsolete = params.ObsoleteParam("obsolete", "not included in params") assert set(params.iter_params(Test())) == {"p1", "p2"}
def __getstate__(self): state = {} for key in iter_params(self._configures): param = self._clsparams.get_param(key) if self in param: state[key] = param.__get__(self, type(self)) state.update(self.__dict__) return state
def assert_is_deepcopy(cp, original): assert cp is not original # ensures separate parameters for param in iter_params(cp): param_inst = getattr(cp, param) if isinstance(param_inst, (nengo.solvers.Solver, nengo.base.NengoObject)): assert_is_copy(param_inst, getattr(original, param)) elif is_array_like(param_inst): assert np.all(param_inst == getattr(original, param)) else: assert param_inst == getattr(original, param)
def assert_is_deepcopy(cp, original): assert cp is not original # ensures separate parameters for param in iter_params(cp): param_inst = getattr(cp, param) if isinstance(param_inst, nengo.solvers.Solver) or isinstance( param_inst, nengo.base.NengoObject): assert_is_copy(param_inst, getattr(original, param)) elif is_array_like(param_inst): assert np.all(param_inst == getattr(original, param)) else: assert param_inst == getattr(original, param)
def resolve_default(cls, param): if inspect.ismodule(param.default): return DisplayDefault(param.default.__name__) elif param.default is not Default: return param.default else: for cls_param in (getattr(cls, name) for name in iter_params(cls)): if cls_param.name == param.name: return DisplayDefault("Default<{!r}>".format( cls_param.default)) warnings.warn("Default value for argument {} of {} could not be " "resolved.".format(param.name, cls)) return param.default
def __init_subclass__(cls, backing_class, **kwargs): unsupported_params = [] for param_name in p.iter_params(backing_class): param = getattr(backing_class, param_name) if (param.name not in vars(cls) and type(param) in cls.paramTypeToGqlType): cls.bind_param(param) else: unsupported_params.append(param) setattr(cls, 'unsupported_params', tuple(unsupported_params)) super().__init_subclass__(**kwargs)
def params(self): """Returns a list of parameter names that can be set.""" return list(iter_params(self))