def separate_method_and_properties(self, c): """ Treatment of properties Parameters ----------- method_list : a generator of the methods to treat Returns -------- Tuple (proplist, methodlist) where proplist : a list of property_ methodlist : the others methods """ method_list = list(self.get_public_methods(c)) # MUST be a list, or the generator will be exhausted later in mlist = ... if not self.use_properties : return method_list, () class property_: def __init__ (self, **kw) : self.__dict__.update(kw) def maybe_prop(m): return len(list(CL.get_params(m))) == 0 and not m.is_static_method() plist1 = [m for m in method_list if maybe_prop(m)] mlist = [m for m in method_list if not maybe_prop(m)] plist = [] OUT, SEP = '', ' ' for m in plist1: n, set_m = m.spelling, None if n.startswith('set_') : continue # do nothing, will be treated with the get_ if n.startswith('get_') : # treat the corresponding setter n = n[4:] set_m = next( (m for m in plist1 if m.spelling == 'set_' + n), None) if set_m : p = list(CL.get_params(set_m)) if set_m.result_type.spelling == "void" and len(p) ==1 : if not util.decay(p[0].spelling) == m.result_type.spelling : OUT += SEP + "Warning :\n" OUT += SEP + " in get_%s/set_%s\n" %(X,X) OUT += SEP + " The type taken from set_%s is not the return type of get_%s\n"%(X,X) OUT += SEP + " Expected %s\n"%m.result_type.spelling OUT += SEP + " Got %s\n"% decay(p[0].spelling) OUT += SEP + " I am not adding the setter to the property\n" set_m = None OUT += SEP + "%s %s\n" %(m.spelling, set_m.spelling if set_m else '') plist.append(property_(name= n, doc = doc.make_doc(m), getter = m, setter = set_m)) if OUT: print " Class %s : transforming to property : \n%s"%(c.spelling, OUT) return mlist, plist
def separate_method_and_properties(self, c): """ Treatment of properties Parameters ----------- method_list : a generator of the methods to treat Returns -------- Tuple (proplist, methodlist) where proplist : a list of property_ methodlist : the others methods """ method_list = list( self.get_public_methods(c) ) # MUST be a list, or the generator will be exhausted later in mlist = ... if not self.use_properties: return method_list, () class property_: def __init__(self, **kw): self.__dict__.update(kw) def maybe_prop(m): return len(list( CL.get_params(m))) == 0 and not m.is_static_method() plist1 = [m for m in method_list if maybe_prop(m)] mlist = [m for m in method_list if not maybe_prop(m)] plist = [] OUT, SEP = '', ' ' for m in plist1: n, set_m = m.spelling, None if n.startswith('set_'): continue # do nothing, will be treated with the get_ if n.startswith('get_'): # treat the corresponding setter n = n[4:] set_m = next((m for m in plist1 if m.spelling == 'set_' + n), None) if set_m: p = list(CL.get_params(set_m)) if set_m.result_type.spelling == "void" and len(p) == 1: if not util.decay( p[0].spelling) == m.result_type.spelling: OUT += SEP + "Warning :\n" OUT += SEP + " in get_%s/set_%s\n" % (X, X) OUT += SEP + " The type taken from set_%s is not the return type of get_%s\n" % ( X, X) OUT += SEP + " Expected %s\n" % m.result_type.spelling OUT += SEP + " Got %s\n" % decay(p[0].spelling) OUT += SEP + " I am not adding the setter to the property\n" set_m = None OUT += SEP + "%s %s\n" % (m.spelling, set_m.spelling if set_m else '') plist.append( property_(name=n, doc=doc.make_doc(m), getter=m, setter=set_m)) if OUT: print " Class %s : transforming to property : \n%s" % ( c.spelling, OUT) return mlist, plist