enthought/traits — pull request #23 by satra (2012-07-13 13:00:36+00:00)
Title: fix: resolve pickling and deepcopying bug with dynamically added traits (closes #2 and #16)

thanks to a pointer from @rkern, this might actually resolve the bugs listed in #2 and #16. however somebody with knowledge of traits should see if making this instance related changes creates other problems.

i didn't know where to add tests but the following test would fail currently and would get addressed by the changes in the pr.

```
def test_hastraits_pickle_deepcopy():
from cPickle import dumps, loads
a = HasTraits()
a.add_trait('foo', Int)
a.foo = 1
assign_a = lambda : setattr(a, 'foo', 'a')
yield assert_raises, Exception, assign_a
pkld_a = dumps(a)
unpkld_a = loads(pkld_a)
assign_a_again = lambda : setattr(unpkld_a, 'foo', 'a')
yield assert_raises, Exception, assign_a_again
copied_a = deepcopy(a)
assign_a_again = lambda : setattr(copied_a, 'foo', 'a')
yield assert_raises, Exception, assign_a_again
```