Created
October 7, 2013 16:01
-
-
Save pierre-haessig/6870346 to your computer and use it in GitHub Desktop.
A bug with add_trait ?
-> is there a need to call a "register" function after adding a trait ?
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" A bug with add_trait ? | |
-> is there a need to call a "register" function after adding a trait ? | |
Documentation reference for `add_trait` : | |
http://docs.enthought.com/traits/traits_user_manual/advanced.html#per-object-trait-attributes | |
Pierre Haessig — October 2013 | |
""" | |
import traits | |
from traits.api import HasTraits, Float | |
print(traits.__version__) | |
# -> 4.3.0 | |
class A(HasTraits): | |
param1 = Float(1) | |
a = A() | |
print(a.get()) | |
# -> {'param1': 1} | |
# Add a trait | |
a.add_trait('param2', Float(2)) | |
print(a.get()) | |
# -> {'param1': 1} | |
# -> 'param2' is missing ! | |
# Visit the trait: | |
a.param2 | |
# Now param2 is visible | |
print(a.get()) | |
# -> {'param2': 2, 'param1': 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment