def get_property_names(obj): if hasattr(obj, "property_dict"): return obj.property_dict.keys() return [ name for name in get_all_params(obj) if isinstance(obj.get_member(name), Property) ]
def process_kwargs(self, kwargs): """Goes through all_params and sets the attribute if it is included in kwargs, also popping it out of kwargs. if the param is tagged with "former", the kwarg is added back using the value of the param. Returns the processed kwargs""" for arg in get_all_params(self): #get_all_tags(self, "former"): if arg in kwargs: setattr(self, arg, kwargs[arg]) val = kwargs.pop(arg, None) key = get_tag(self, arg, "former", False) if key is not False: if val is None: val = getattr(self, arg) kwargs[key] = val return kwargs
def process_kwargs(self, kwargs): """Goes through all_params and sets the attribute if it is included in kwargs, also popping it out of kwargs. if the param is tagged with "former", the kwarg is added back using the value of the param. Returns the processed kwargs""" for arg in get_all_params(self): #get_all_tags(self, "former"): if arg in kwargs: setattr(self, arg, kwargs[arg]) val=kwargs.pop(arg, None) key=get_tag(self, arg, "former", False) if key is not False: if val is None: val=getattr(self, arg) kwargs[key]=val return kwargs
def __init__(self, **kwargs): super(Test, self).__init__(**kwargs) for param in get_all_params(self): typer=get_type(self, param) _setup_property_fs(self, param, typer)
a=Int().tag(c=4, private=True) b=Float() c=Int().tag(sub=True) @private_property def main_params(self): return ["c"] t=Test() print print "get_reserved_names returns all names of members tagged as private=True" print 'get_reserved_names(t)' print get_reserved_names(t) print print "get_all_params returns all names of members not tagged as private=True" print 'get_all_params(t)' print get_all_params(t) print print "get_all_main_params returns all params in all_params that are not tagged as sub" print 'get_all_main_params(t)' print get_all_main_params(t) print print "get_main_params defaults to get_all main_params but can be overwritten in the class" print 'get_main_params(t)' print get_main_params(t) print log_info("test code:") print """class Test(Atom): a=Int().tag(c=4) b=Int().tag(typer=str) t=Test()"""
def all_params(self): return get_all_params(self)
def __init__(self, **kwargs): super(Test, self).__init__(**kwargs) for param in get_all_params(self): typer = get_type(self, param) _setup_property_fs(self, param, typer)
c = Int().tag(sub=True) @private_property def main_params(self): return ["c"] t = Test() print print "get_reserved_names returns all names of members tagged as private=True" print 'get_reserved_names(t)' print get_reserved_names(t) print print "get_all_params returns all names of members not tagged as private=True" print 'get_all_params(t)' print get_all_params(t) print print "get_all_main_params returns all params in all_params that are not tagged as sub" print 'get_all_main_params(t)' print get_all_main_params(t) print print "get_main_params defaults to get_all main_params but can be overwritten in the class" print 'get_main_params(t)' print get_main_params(t) print log_info("test code:") print """class Test(Atom): a=Int().tag(c=4) b=Int().tag(typer=str) t=Test()"""
def get_property_names(obj): if hasattr(obj, "property_dict"): return obj.property_dict.keys() return [name for name in get_all_params(obj) if isinstance(obj.get_member(name), Property)]