Skip to content

Instantly share code, notes, and snippets.

@pierre-haessig
Created October 7, 2013 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierre-haessig/6870346 to your computer and use it in GitHub Desktop.
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 ?
#!/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