-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminating _update_state
?
#830
Comments
Thanks for the great write-up! It's an exact recollection of what happened and why I had to add I'd be in favor of requiring users to specific
Dealing with To complete the list of attributes than can be dynamically computed, there's also |
I think the Tuple length imputation is safe and reasonably clean, so it sounds like @maximlt votes for changing |
Thanks for the detailed writeups both of you. I fully agree with @maximlt's summary and agree that making |
Ok, sounds good. That option controls whether a given value is validated against the list of allowed values, i.e., it checks that the value is allowed when someone sets the value. Suggestions for another name, now that people will need to learn about this option? |
Not sure I have anything good. In the Panel context this will line up with Autocomplete and MultiChoice widgets which allow either restricting the options or adding new options. There it's called |
That's an argument for keeping the status quo, but if anyone does have a really clear name, we can add that as an alias when we come up with it and make our docs focus on that instead. |
Agreed, my vote is to take no action on renaming |
We're agreed about keeping the name of |
No my misunderstanding, that all sounds fine. In the end _update_state is just an implementation detail though so no opinion whether to remove it, if it gets eliminated by making those changes then that's good too. |
I'm going to try to remove |
It's undocumented, but if it's required for any user-visible behavior, better for us to find that out now! |
Also, I get the idea to clean up some method if we can. But providing a way to update the state of a Parameter doesn't sound too bad to me. Parameters could all be lazily created and be finalized when bound to a Parameterized class. |
Sure. On balance if we don't need that I want to prioritize someone being able to read Param's code and understand what happens when, which is quite difficult given the Parameter itself, its metaclass, Parameterized, and its metaclass, so anything that can be omitted from that control flow is a win. |
#794 introduced a new
Parameter._update_state
method that runs after the Parameter is installed into a Parameterized, to support any Parameter-specific computations that cannot complete until then.Adding this mechanism was required once we used the Sentinel approach (
param.Undefined
) to provide systematic support for inheritance of Parameter slot values, including slots that depend on the Parameter value, since that value might be inherited and thus cannot be fully determined until the Parameter is installed into the Parameterized class hierarchy that owns it. I.e., first the constructor for a Parameter completes, then it gets installed into a Parameterized, and only then can the values of anyUndefined
slots be known.It's difficult to trace all of this through and I keep forgetting the details, so I'm filing this issue to capture for posterity precisely what we would lose if we did not have
_update_state
. Specifically, we would lose the ability to have a computed default for theSelector.check_on_set
slot. ASelector
can either have a fixed list of allowable items, or it can be a handy way to keep track of all the previous items used so far (e.g. for populating a Selector widget in a GUI), andcheck_on_set
determines which of those behaviors will be provided. Most people don't currently have to set thecheck_on_set
slot explicitly, because when they provide an explicitobjects
slot value,check_on_set
defaults to True , and otherwisecheck_on_set
defaults to False. I.e. if we have objects, assume those are the only objects allowed, and if we don't, assume we're just collecting values.That's all easy enough to implement, but the tricky bit is that when we do want to collect values, we need to collect the initial default value as well, and that value is not necessarily available until after slot inheritance, which is done after the constructor completes. So @maximlt implemented
_update_state
to provide a hook for recording the fact that the default value needs to be put onto theobjects
list/dict, but not actually doing it eagerly in the constructor because (a) the value isn't actually known yet, and (b) even if we do know the value (e.g. when it's provided explicitly in the constructor call), populating it eagerly will break the logic for thecheck_on_set
default value, because theobjects
list/dict will appear to have been populated by the user.So, what would it take to eliminate this quite hairy logic? I think the results would be an annoyance for users and a compatibility issue, but they would have been reasonable policies to have if we'd done them from the start. Specifically, we'd:
check_on_set
explicitly. It would have to default to a simpleTrue
for safety, to ensure that checking is done when expected. If a user doesn't want checking, they'd have to explicitly changecheck_on_set
to False, rather than simply not supplying objects, or they will get an exception.Parameter.allow_None
.allow_None
normally defaults to False, but it is automatically updated toTrue
if the default value (whether inherited or not) isNone
. This is a convenience that reflects the fact that most uses of a None value are for a default, awaiting a user filling in a real value later, which means that right now almost no user ever needs to specifyallow_None
explicitly. With this change, users would be required to specifyallow_None=True
explicitly whenever they use a default ofNone
, or they will get an exception.If we went with these more explicit but less friendly policies, we'd eliminate
_update_state
(about 10 lines of mysterious code),__compute_selector_checking_default
(8 lines), and_set_allow_None
and relatedallow_None
defaults handling (12 lines). 30 lines of code isn't much, but it's all code that is deeply confusing to trace through, so as a programmer I'd be very happy to see it go. Plus as a user it's much more explicit and easy to reason without it; I just have to deal with the exception when it's raised, and it should be obvious what to do.Still, the current behavior is convenient, and making such a change now seems like it would disrupt quite a lot of existing code (anything using Selectors without explicit
objects
lists or any Parameter with a default value of None). Does anyone think it's worth the disruption? Moving to 2.0 as we are currently doing seems like the only possible chance for such a disruption, if we have a consensus behind it.The text was updated successfully, but these errors were encountered: