# HG changeset patch # User Thinker K.F. Li # Date 1297562673 -28800 # Node ID 1a4d15fe2c6267fca11e1bf86b7651fe2e1da970 # Parent 17fa5d78200beb343ff31fd7b0931d23f45e9323 Fix the issue for name confliction between two used traits. - When a class use two or more traits, and the name of a method from one trait conflicts with an attribute from another one, composite will be fault for setting method proxys. - Solution is to skip attributes that is not callable when setting proxys. diff -r 17fa5d78200b -r 1a4d15fe2c62 pyink/trait.py --- a/pyink/trait.py Sun Feb 13 01:17:17 2011 +0800 +++ b/pyink/trait.py Sun Feb 13 10:04:33 2011 +0800 @@ -150,7 +150,7 @@ continue value = getattr(a_trait, attr) - if isinstance(value, require): + if isinstance(value, require) or not callable(value): continue attrname_cnts[attr] = attrname_cnts.setdefault(attr, 0) + 1 @@ -187,8 +187,7 @@ value = getattr(derived, attr) if not callable(value): - raise TypeError, \ - '%s.%s is not a callable' % (repr(a_trait), attr) + continue func = value.im_func proxy = trait_method_proxy(derived, func) @@ -313,17 +312,31 @@ @trait class hello(object): msg = require + bye_provide = require def hello(self, name): return self.msg + ' hello ' + name + + def hello_provide(self): + return 'hello provide' + + def require_bye(self): + return self.bye_provide() pass @trait class bye(object): msg = require + hello_provide = require def bye(self, name): return self.msg + ' bye ' + name + + def bye_provide(self): + return 'bye provide' + + def require_hello(self): + return self.hello_provide() pass @composite @@ -339,5 +352,7 @@ o = hello_bye() assert o.hello1('Miky') == 'hello_bye_msg1 hello Miky' assert o.bye('Miky') == 'hello_bye bye Miky' + assert o.require_bye() == 'bye provide' + assert o.require_hello() == 'hello provide' print 'OK' pass