Re: [Modeling-users] dynamic, metaclasses and Virtual properties
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-08-07 13:30:47
|
Hi Erny and all, On Wed, 30 Jun 2004, Ernesto Revilla <er...@si...> wrote: [original post can be found at: https://sf.net/mailarchive/forum.php?thread_id=3D5035017&forum_id=3D10674] > I think that Python has a design error with properties, but it is easy to > correct this.=20 [demonstration that properties aint behaving very good when it comes to inheritance] > In Modeling, when inheriting from class created with properties (dynamic)= , it > does NOT the inherited methods. Is this reasonable? You're right, this needs some attention, really. Could you submit this as a bug report or as a patch proposal @sf.net please? > Here I have attached a > little patch for dynamic.py. I made a local function mkProp, so that vari= able > binding is correct, otherwise it does not work the way it should. Can you be more explicit on this point? > Just a > remark about the setter. As in the original code, a virtual setter is cre= ated > only if the attribute is settable in the base class. In this case, we hav= e two > alternatives: 1. do not create a setter, as the original code, 2. create > always a virtual setter and the setter in the base class raises a > ReadOnlyAttributeException. (This is was I have done in a experimental > framework.) For the moment being we're not handling any 'readOnly' properties on attributes --and the one in entity is still ignored for now, so I can't really see whazt your point is, I suspect I'm misunderstanding something here. Oh, and BTW sorry for taking such a long time to answer :/ -- S=E9bastien. > Index: dynamic.py > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/modeling/ProjectModeling/Modeling/dynamic.py,v > retrieving revision 1.1 > diff -u -r1.1 dynamic.py > --- dynamic.py 16 Feb 2004 20:01:06 -0000 1.1 > +++ dynamic.py 30 Jun 2004 16:07:47 -0000 > @@ -144,10 +144,16 @@ > def add_properties(aClass, entity): > for p in entity.classProperties(): > #print 'defining prop: ', p.name() > - part_func_name=3DcapitalizeFirstLetter(p.name()) > - prop=3Dproperty(getattr(aClass, 'get'+part_func_name), > - getattr(aClass, 'set'+part_func_name), None) > - setattr(aClass, p.name(), prop) > + part_func_name=3DcapitalizeFirstLetter(p.name()) > + readonly=3Dnot hasattr(aClass,'set'+part_func_name) > + def mkProp(name, readonly=3D0): > + getter=3Dlambda s: getattr(s,'get'+name)() > + if readonly: > + setter=3DNone > + else: > + setter=3Dlambda s, v: getattr(s,'set'+name)(v) > + return property(getter, setter) > + setattr(aClass, p.name(), mkProp(part_func_name, readonly)) >=20=20=20=20=20=20 > def build(model, define_properties=3D0): > module_name=3Dmodel.packageName() |