dynamic metaclass overwrites custom methods

[email protected] Wed, 01 Sep 2004 12:08:27 +1200
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Hello,

if I define:

class A:
    __metaclass__ = dynamic.CustomObjectMeta
    entityName = 'A'
    mdl_define_properties = 1

    def setName( self, value ):
	pass

name being a class property, when the metaclass __new__ method populates
the instance with code it overrides setName with the stock one.
My fix here is to check for the existence of the method before overriding
and rename it to 'mdl_'+method_name (which might not be inline
with your naming conventions) in case it's already there.

patch follows

comments anyone?

cheers
--
Delio

diff -aur /home/delio/tmp/ModelingCore-0.9-pre-17.1/Modeling/dynamic.py ./dynamic.py
--- /home/delio/tmp/ModelingCore-0.9-pre-17.1/Modeling/dynamic.py       2004-02-17 09:01:06.000000000 +1300
+++ ./dynamic.py        2004-08-31 19:51:40.000000000 +1200
@@ -265,6 +265,9 @@
   func_name, c=getter_code(prop)
   info(classdict, "adding getter: %s"%func_name)
   getter=function_for_code(c, func_name)
+  if classdict.has_key( func_name ):
+    func_name = 'mdl_' + func_name
+    info(classdict, "getter already defined renaming to: %s"%func_name)
   classdict[func_name]=getter
 
 def define_getters(entity, classname, classdict):
@@ -277,6 +280,9 @@
   for func_name, c in names_and_funcs:
     info(classdict, "adding setter: %s"%func_name)
     setter=function_for_code(c, func_name)
+    if classdict.has_key( func_name ):
+        func_name = 'mdl_' + func_name
+        info(classdict, "setter already defined renaming to: %s"%func_name)
     classdict[func_name]=setter
 
 def define_setters(entity, classname, classdict):


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click