Mercurial > MadButterfly
diff pyink/trait.py @ 1351:1a4d15fe2c62
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.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 13 Feb 2011 10:04:33 +0800 |
parents | b0e54ae756f8 |
children | 28769a82a72d |
line wrap: on
line diff
--- 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