Created
March 18, 2010 15:42
-
-
Save satra/336482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TraitedSpec2(traits.HasTraits): | |
trigger = traits.Event | |
hashval = traits.Property(depends_on='trigger') | |
@traits.cached_property | |
def _get_hashval(self): | |
print "calc hash" | |
import numpy as np | |
return np.random.random() | |
def _anytrait_changed(self, name): | |
if name in ['trait_added', 'trait_modified', 'hashval', 'trigger']: | |
return | |
self.trigger = True | |
class TraitedSpec3(traits.HasTraits): | |
trigger = traits.Event | |
hashval = traits.Property(depends_on='trigger') | |
@traits.cached_property | |
def _get_hashval(self): | |
print "calc hash" | |
import numpy as np | |
return np.random.random() | |
@traits.on_trait_change('*') | |
def foo_changed(self, name): | |
if name != 'trigger': | |
self.trigger = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [16]: class foo(nib.TraitedSpec2): | |
goo = nib.traits.Float | |
In [18]: a = foo() | |
In [19]: a.hashval | |
calc hash | |
Out[19]: 0.3683029010095128 | |
In [20]: a.hashval | |
Out[20]: 0.3683029010095128 | |
In [21]: a.goo = 1.1 | |
calc hash | |
In [22]: a.hashval | |
Out[22]: 0.047413607727976648 | |
In [23]: a.goo = 1.1 | |
In [24]: a.hashval | |
Out[24]: 0.047413607727976648 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [9]: class foo(nib.TraitedSpec3): | |
goo = nib.traits.Float | |
In [11]: a = foo() | |
In [12]: a.hashval | |
calc hash | |
Out[12]: 0.57163717292479677 | |
In [13]: a.hashval | |
Out[13]: 0.57163717292479677 | |
In [14]: a.goo = 1.1 | |
Exception occurred in traits notification handler. | |
Please check the log file for details. | |
Exception occurred in traits notification handler for object: <__main__.foo object at 0x102bc5290>, trait: goo, old value: 0.0, new value: 1.1 | |
Traceback (most recent call last): | |
File "/Library/Python/2.6/site-packages/Traits-3.3.1-py2.6-macosx-10.6-universal.egg/enthought/traits/trait_notifiers.py", line 586, in rebind_call_4 | |
object, trait_name, old, new ) | |
File "/Library/Python/2.6/site-packages/Traits-3.3.1-py2.6-macosx-10.6-universal.egg/enthought/traits/trait_notifiers.py", line 424, in dispatch | |
handler( *args ) | |
File "/Library/Python/2.6/site-packages/Traits-3.3.1-py2.6-macosx-10.6-universal.egg/enthought/traits/traits_listener.py", line 474, in handle_dst | |
object, name = self.next.register( new ) | |
File "/Library/Python/2.6/site-packages/Traits-3.3.1-py2.6-macosx-10.6-universal.egg/enthought/traits/traits_listener.py", line 397, in register | |
trait = new.base_trait( name ) | |
AttributeError: 'float' object has no attribute 'base_trait' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment