param
param copied to clipboard
Add mechanism to specify that a parameter must be set?
Is it possible to make a Parameter that has to be set? I.e. if not specified on instance creation, an exception will be raised?
Not currently supported directly. You could approximate it by making the default value be None and adding an explicit test to the object's constructor to raise an exception if the value is still None after the super()'s constructor is called.
Ahh. I'm currently very much hit by this lack of functionality in my daily work. See https://discourse.holoviz.org/t/how-to-make-parameter-values-mandatory/5124. I had forgotten about this issue. I can also see I've requested this functionality before in #574
@philippjfr suggested on Discourse to add a required
argument to Parameter
.
It's not clear in this thread if the functionality has been implemented or what the api will look like.
Is there a roadmap to enable a required
argument to Parameter
as @MarcSkovMadsen suggests?
Thanks team, looks like an intricate part of param.
Hi @LinuxIsCool,
This feature hasn't yet been merged into Param and I'm not sure yet about the right API. Marc indeed opened a PR to add a required
attribute to Parameter, the idea to pass a specific variable to the default value to signal it's required (e.g. Number(default=Required)
) has also been in the air. Additionally what I wanted to do is to check how other similar libraries approach that (dataclass, attrs, pydantic). Generally Param should offer more options so that users don't have to override __init__
as it's prone to mistakes.
We have decided not to include this feature in Param 2.0 just for the sole purpose to reduce its scope and get it released, it's been long enough in the making!
Right; this feature has been waiting on 2.0 to be released so that it does not conflict with other APIs we've added, but we should be able to add this in a fast followon after 2.0 is released. We're on release candidate 6 now, I think, so very close!
Now that 2.0 has been released and out for a while, is there any possibility this will be looked into again? Attempting to adopt Param/Panel in a project I'm using has been a bit difficult after coming from the extensive validation possibilities of Pydantic, and enforcing things like required params would help ease some of that. I saw https://github.com/holoviz/param/pull/724, where implementation was still being discussed, and perhaps that's easier to settle after Param 2's release?