_setup_dynamic_initializer simplified#28
_setup_dynamic_initializer simplified#28SylvainCorlay wants to merge 3 commits intoipython:masterfrom
Conversation
There was a problem hiding this comment.
I dislike this change - it makes the API more stateful, because _set_default_value_at_instance_init() now relies on _setup_dynamic_initializer having been called first. But in #23, you remove this method entirely. The two PRs will conflict - what is the relationship between them?
There was a problem hiding this comment.
I already rebased the #23 on this PR. Regarding statefulness, _trait_dyn_inits is also used in __get__.
The task of _setup_dynamic_initializer is to set this variable.
There was a problem hiding this comment.
OK, should we just be reviewing #23 as a single unit now?
There was a problem hiding this comment.
- _setup_dynamic_initializer simplified #28 does not change behavior. It is more of a cosmetic change and could be merge more easily.
- Simplify deferred creation of default values #23 is more involving since it changes how default values are initialized.
|
Thanks for looking at this. I guess I am trying to split things too much into small changes to get them in. So here is the idea: One issue is that |
e3d6f08 to
2c6056d
Compare
2c6056d to
95b9470
Compare
…c initializers must be too.
|
As mentioned on #23, I'm not happy about a simplification PR that adds a new public API method. From the diff, this does not now appear to make the code simpler - has what you're trying to achieve changed? |
|
Too me, having |
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.
_setup_dynamic_initializerused to return a boolean on whether there is a dynamic initializer for a given trait. It does not anymore.Two remarks though:
instance_initis supposed to correspond to the part or the initialization that depends on theHasTraitsinstance.All of what is currently in the implementation of
instance_initfor our trait types does not actually depend onobj. It could simply be part of__init__. There is no real reason to keep it there._setup_dynamic_initializercould be moved toTraitType.instance_init.