add_trait doesn't make traits "immediately available"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

add_trait doesn't make traits "immediately available"

Pierre Haessig
Hi,

I put an issue on GitHub (https://github.com/enthought/traits/issues/84)
but maybe I should have asked on the ML instead :

Starting using the `add_trait` method, I noticed a strange behavior.
(using traits 4.3.0)

When adding a new trait with `add_trait`, it is not accessible before
"visiting it" :

```
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}
```

(see https://gist.github.com/pierre-haessig/6870346 for complete script)

Is this an expected behavior or a bug ? Should I call some kind of *"do
register my trait"* method ?

best,
Pierre


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

signature.asc (918 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: add_trait doesn't make traits "immediately available"

Pierre Haessig
Hi,

Le 14/10/2013 15:06, Pierre Haessig a écrit :

> I put an issue on GitHub (https://github.com/enthought/traits/issues/84)
> but maybe I should have asked on the ML instead :
>
> Starting using the `add_trait` method, I noticed a strange behavior.
> (using traits 4.3.0)
>
> When adding a new trait with `add_trait`, it is not accessible before
> "visiting it" :
>
> ```
> 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}
> ```
>
> (see https://gist.github.com/pierre-haessig/6870346 for complete script)
>
> Is this an expected behavior or a bug ? Should I call some kind of *"do
> register my trait"* method ?
>
Since I got no feedback, I was wondering if there is a better place to
ask this question. Should I ask on stackoverflow ?

Also, if the issue I opened is not bug
(https://github.com/enthought/traits/issues/84), maybe somebody can
close it ?

best,
Pierre



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

signature.asc (915 bytes) Download Attachment