Simplify deferred creation of default values#23
Simplify deferred creation of default values#23SylvainCorlay wants to merge 4 commits intoipython:masterfrom
Conversation
104d9df to
deef552
Compare
|
@takluyver let me know what you think. This is completely deferring the initialization of default values to the first |
2b47c9f to
5ac9d8b
Compare
|
This actually does what @minrk was suggesting there ipython/ipython#8107 (comment) . This should make a lot of the |
674c49f to
1793f0c
Compare
There was a problem hiding this comment.
It seems like these removed tests should still be failing, rather than removed.
There was a problem hiding this comment.
If it requires adding a request for the trait, that's okay, too, but the tests shouldn't be removed altogether.
ee5a17f to
776cb87
Compare
|
Rebased upon #28 |
776cb87 to
dc8dfcb
Compare
|
I think we can avoid the behaviour change if, in try:
old_value = obj._trait_values[self.name]
except KeyError:
old_value = Undefinedto this: try:
old_value = obj._trait_values[self.name]
except KeyError:
old_value = self.default_value
|
dc8dfcb to
83bb075
Compare
…c initializers must be too.
b59b345 to
4b3242f
Compare
|
@takluyver I tried your suggestion but it still fails the test for bad defaults. |
There was a problem hiding this comment.
I'd like to avoid adding yet another method, especially in a PR called 'Simplify...'
There was a problem hiding this comment.
This is part of #28, can we debate this there?
There was a problem hiding this comment.
It seemed like these two PRs were part of the same thing, but I guess that's not how you see it? Should I ignore this one until we have reached a decision on #28?
|
It looks like you've got rid of all the changes to tests - does that mean that it no longer changes behaviour? |
|
No, a commit is missing. Just need a minute. |
This is an alternative to ipython#23 and ipython#28 There is already a mechanism for dynamic default values with _foo_default methods, which are not called unless needed. This makes the default values for Instance traitlets use that same mechanism, avoiding instantiating classes unless those traitlets are explicitly requested without being assigned first. Along the way, two other changes to behaviour, and hence to tests, came in. Dict traitlets are based on Instance, so their behaviour changes in the same way. And a Type() traitlet with no class specified now gets a default value of object instead of None, because the former is valid when allow_none is True. It was also possible to clean up some parts of the machinery.
|
Closing this one for now, since it changes the behavior and we are close to 4.0. |
This is an attempt to simplify initialization of default values.
The behavior is slightly different in that now:
Previously, the first example would not trigger a trait notification since 0 is equal to the default value which was initialized. I realize this is quite a change, but it really simplifies the code.